Adding additional fields to ElasticSearch terms aggregation

后端 未结 2 1999
执笔经年
执笔经年 2021-02-02 09:06

Indexed documents are like:

{
  id: 1, 
  title: \'Blah\',
  ...
  platform: {id: 84, url: \'http://facebook.com\', title: \'Facebook\'}
  ...
}
<
2条回答
  •  隐瞒了意图╮
    2021-02-02 09:17

    If you don't necessarily need to get the value of platform.id, you could get away with a single aggregation instead using a script that concatenates the two fields name and url:

    aggs: {
      platforms: {
        terms: {script: 'doc["platform.name"].value + "," + doc["platform.url"].value'}
      }
    }
    

提交回复
热议问题