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

前端 未结 5 1327
無奈伤痛
無奈伤痛 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:13

    I think you would need to add another "aggs" to it. But it would not be in the format in which you want but as another field in the output , reason being currently you are aggregating based on "agency_code" and the doc_count shows how many times the particular agency code occurs. Now when you want to aggregate it based on "agency_name" the field might in different documents than "agency_code" and in different numbers as well , if they always exist in pair than this parent-child indexing might be of some help.

    https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-parent-child.html

提交回复
热议问题