How to retrieve more data in aggregation?

前端 未结 1 1390
醉话见心
醉话见心 2021-01-26 03:16

I am using following aggregation:

searchOptions.aggs = {
  categories: {
    terms: {
      field: \"CategoryId\"
    }
  }
}

This works howeve

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 03:38

    If you want to get category name for that id then,

    {
       "size": 0,
       "aggs": {
          "category": {
             "terms": {
                "field": "categoryId"
             },
             "aggs":{
                 "categoryName" :{
                     "terms" :{
                         "field" :"categoryName"
                     }
                 }
             }
          }
       }
    }
    

    So, sub-aggregation(which is nested in above) gives you categoryName for its id.

    0 讨论(0)
提交回复
热议问题