如何基于当前agg进行Elasticsearch Agg查询?

时间:2019-01-16 18:12:19

标签: node.js elasticsearch elasticsearch-aggregation

我的文档看起来像这样

{ cool_things: [{ name, id }, { name, id }] }

我将如何找到我目前正在汇总的那个ID。例如,这是我正在使用的查询。

params.body.aggs = {
    uniqueCoolThings: {
      terms: {
        field: 'cool_things.name.keyword'
      },
      aggs: {
        value: {
          top_hits: {
            size: 1,
            _source: {
              includes: ['cool_things.id', 'cool_things.name.keyword']
            }
          }
        }
      }
    }
  }
}

这将返回

...hits._source: {
    uniqueCoolThings: [
        {
            "id": 500,
            "name": "Bob Sagget"
        },
        {
            "id": 501,
            "name": "Matt Damon"
        }
     ]
} ...

我想知道如何执行where条件,以便它只返回与当前使用的唯一cool_things.name.keyword匹配的ID。

我需要获取所有unique_cool物品的列表,然后通过响应返回他们的ID(如果可以)

任何帮助将不胜感激!!!!

0 个答案:

没有答案