【发布时间】:2021-06-27 23:08:49
【问题描述】:
我在查找重复项时使用以下 ES 查询:
"aggs": {
"duplicates": {
"terms": {
"field": "phone",
"min_doc_count": 2,
"size": 99999,
"order": {
"_term": "asc"
}
},
"aggs": {
"_docs": {
"top_hits": {
"size": 99999
}
}
}
}
}
它运行良好,它返回在本例中为phone 的键,并在其中返回所有匹配项。主要问题正是,在 _source 上它带来了所有内容,这在我的案例中有很多字段,我想指定只带我需要的那些。返回的示例:
"duplicates": {
"1": {
"key": "1",
"doc_count": 2,
"_docs": {
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "local:company_id:1:sync",
"_type": "leads",
"_id": "23",
"_score": 1,
"_source": {
"id": 23,
"phone": 123456,
"areacode_id": 426,
"areacode_state_id": 2,
"firstName": "Brayan",
"lastName": "Rastelli",
"state": "", // .... and so on
我想指定将在_source 上返回的字段,可以吗?
我遇到的另一个问题是我想按特定字段(id)对聚合结果进行排序,但是如果我输入任何字段名称而不是 _term,则会出现错误。
谢谢!
【问题讨论】:
标签: elasticsearch aggregation elasticsearch-aggregation