0
我正在嘗試使用基數聚合來計算不同的值。篩選器聚合內的基數聚合
這裏是我的查詢中使用match_phrase一段文字
{
"size": 100,
"_source":["awardeeName"],
"query": {
"match_phrase":{"awardeeName" :"The President and Fellows of Harvard College" }
},
"aggs":{
"awardeeName": {
"filter" : { "query": { "match_phrase":{"awardeeName" :"The President and Fellows of Harvard College" }}},
"aggs": {
"distinct":{"cardinality":{ "field": "awardeeName"}}
}
}
}
}
查詢,使用相同的詞組匹配聚集,然後調用基數, 結果,命中數和聚集fitler比賽,但基數顯示不同數量令人吃驚比過濾器和總點擊較大,這裏是結果
{
"took": 37,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 13.516766,
"hits": [
{
"_index": "development",
"_type": "document",
"_id": "140a3f5b-e876-4542-b16d-56c3c5ae0e58",
"_score": 13.516766,
"_source": {
"awardeeName": "The President and Fellows of Harvard College"
}
},
{
"_index": "development",
"_type": "document",
"_id": "5c668b06-c612-4349-8735-2a79ee2bb55e",
"_score": 12.913888,
"_source": {
"awardeeName": "The President and Fellows of Harvard College"
}
},
{
"_index": "development",
"_type": "document",
"_id": "a9560519-1b2a-4e64-b85f-4645a41d5810",
"_score": 12.913888,
"_source": {
"awardeeName": "The President and Fellows of Harvard College"
}
}
]
},
"aggregations": {
"awardeeName": {
"doc_count": 3,
"distinct": {
"value": 7
}
}
}
}
我期待基數適用於過濾器的結果,但在這種情況下,基數顯示7,爲什麼它顯示7?獨特值如何計數超過總點擊次數?
關鍵字將返回0記錄的情況下匹配查詢的價值'大學',我想通過匹配和match_phrase搜索,保持數據類型文本,有沒有什麼辦法來計算不同的字段值? – user884424
還有一種方法是將此屬性映射爲兩個不同的字段,一個用於使用關鍵字分析器對文本分析器進行全文搜索以及用於不同計數等的其他方法? – user884424
這是正確的,您可能需要一個多字段,即全文搜索字段和另一個帶關鍵字分析器的子字段。 – Val