1 回答
TA贡献1725条经验 获得超7个赞
description.keyword您应该尝试对子字段进行术语聚合:
body = {
"query": {
"match": {"state": query_input}
},
"size":1000,
"aggs": {
"distinct_descriptions": {
"terms": {
"field": "description.keyword"
}
}
}
}
result = con.search(index='data', body=body)
occurrences_list = list()
occurrences_dict = {"description":None, "score":None}
for res in result["aggregations"]["distinct_descriptions"]["buckets"]:
occurrences_dict["description"] = {res['key'] : res['doc_count'] }
occurrences_list.append( occurrences_dict )
for res in result["hits"]["hits"]:
for elem in occurrences_list:
if res["_source"]["description"] == elem['description']:
if not elem["score"]:
elem["score"] = res["_score"]
注意星期一产生的查询,现在还有一个大小参数,否则elasticsearch默认只检索20个命中
添加回答
举报