我試圖計算成分在不同檔案中出現的次數。我的索引體與此類似
index_body = {
"settings":{
"index":{
"number_of_replicas":0,
"number_of_shards":4,
"refresh_interval":"-1",
"knn":"true"
}
},
"mappings":{
"properties":{
"recipe_id":{
"type":"keyword"
},
"recipe_title":{
"type":"text",
"analyzer":"standard",
"similarity":"BM25"
},
"description":{
"type":"text",
"analyzer":"standard",
"similarity":"BM25"
},
"ingredient":{
"type":"keyword"
},
"image":{
"type":"keyword"
},
....
}
}
在成分欄位中,我存盤了每種成分的字串陣列[ingredient1,ingredient2,....]
我有大約 900 份檔案。每個都有自己的成分表。
我試過使用 Elasticsearch 的聚合,但它似乎沒有回傳我所期望的。這是我一直在使用的查詢:
{
"size":0,
"aggs":{
"ingredients":{
"terms": {"field":"ingredient"}
}
}
}
但它回傳這個:
{'took': 4, 'timed_out': False, '_shards': {'total': 4, 'successful': 4, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 994, 'relation': 'eq'}, 'max_score': None, 'hits': []}, 'aggregations': {'ingredients': {'doc_count_error_upper_bound': 56, 'sum_other_doc_count': 4709, 'buckets': [{'key': 'salt', 'doc_count': 631}, {'key': 'oil', 'doc_count': 320}, {'key': 'sugar', 'doc_count': 314}, {'key': 'egg', 'doc_count': 302}, {'key': 'butter', 'doc_count': 291}, {'key': 'flour', 'doc_count': 264}, {'key': 'garlic', 'doc_count': 220}, {'key': 'ground pepper', 'doc_count': 185}, {'key': 'vanilla extract', 'doc_count': 146}, {'key': 'lemon', 'doc_count': 131}]}}}
這顯然是錯誤的,因為我有很多成分。我究竟做錯了什么?為什么只回傳這些?有沒有辦法強制 Elasticsearch 回傳所有計數?
uj5u.com熱心網友回復:
您需要在聚合內指定大小。
{“大小”:0,“聚合”:{“成分”:{“術語”:{“欄位”:“成分”,“大小”:10000}}}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/490110.html
