我有一个Elasticsearch索引,部分内容如下:
...
},
"entity": {
"properties": {
"DateTime": {
"type": "date"
},
"Event": {
"type": "keyword"
},
"Location": {
"type": "keyword"
},
"Organ": {
"type": "keyword"
},
"Person": {
"type": "keyword"
}
}
},
...
我想找到最常出现的人。所以,我通过以下方式查询索引:
{"size":0, "query":{"match_all":{}},"aggs":{"top_locations":{"terms":{"field":"entity.Person","size":1}}}}
和
{"size":0, "query":{"match_all":{}},"aggs":{"top_locations":{"terms":{"field":"entity.Person.keyword","size":1}}}}
问题是第一个查询工作正常,但第二个查询不起作用。
你可以试试这个
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"nested_entity": {
"nested": {
"path": "entity"
},
"aggs": {
"top_people": {
"terms": {
"field": "entity.Person.keyword",
"size": 1
}
}
}
}
}
}