ElasticSearch - How to display an additional field name in aggregation query

前端 未结 5 1328
無奈伤痛
無奈伤痛 2021-02-12 03:51

How can I add a new key called \'agency_name\' in my output bucket.

I am running an aggregation code as shown below

{
  \"aggs\": {
    \"name\": {
             


        
5条回答
  •  不思量自难忘°
    2021-02-12 04:11

    ES has no way of knowing agency_name and agency_code map one-to-one. Therefore I would recommend a number of possible strategies.

    • Don't analyze agency_name and use the term agg over that field. I would be surprised if you actually need to do tokenization of the agency_name.
    • Store the id to name mapping in a relational database or a flat file cache and do the join client side
    • Store the agency documents as another type and make two calls. The first to get the ids and then a second to lookup the agencies by id

    As Aditya Patel mentioned above, parent child relationships may help out as well but I believe you will still have to use one of the above strategies to resolve the id->name mapping.

提交回复
热议问题