我想在 elasticsearch 中進行查詢以回傳重復項,但查詢回傳錯誤 400 并設定 fieldata=True。
我需要在elasticsearch中進行查詢,
我目前有一個查詢:
{
"query": {
"match_all": {}
},
"aggs": {
"duplicateCount": {
"terms": {
"field": "hash_code_document",
"min_doc_count": 2
}
}
}
}
但是在進行查詢時,我得到了這個 400 錯誤:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hash_code_document] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "curriculo-19",
"node" : "QOzYVehEQhezjq1TWxYvAA",
"reason" : {
"type" : "illegal_argument_exception",
"reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hash_code_document] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
}
],
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hash_code_document] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [hash_code_document] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
}
},
"status" : 400
}
我是否需要更改映射才能進行查詢?
uj5u.com熱心網友回復:
看起來您的欄位在映射中定義為“文本”。Elasticsearch 不允許在此類欄位中進行聚合。您需要將映射中的欄位型別更改為“關鍵字”,例如:
"mappings": {
"properties": {
"hash_code_document":{
"type": "keyword"
}
}
}
或者如果您已經有類似的欄位:hash_code_document.keyword,您需要使用它進行聚合
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/452260.html
標籤:弹性搜索
上一篇:Elasticsearch:如何從嵌套檔案聚合到每個主檔案?
下一篇:如何洗掉線性散點圖上的例外值
