查询 ELASTICSEARCH (illegal_argument_exception)
QUERY ELASTISEARCH (illegal_argument_exception)
我想在 elasticsearch 中查询 returns 重复项,但查询 returns 错误 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
}
是否需要更改映射才能进行查询?
看起来您的字段在映射中定义为“文本”。 Elasticsearch 不允许在此类字段中进行聚合。
您需要将映射中的字段类型更改为“关键字”,例如:
"mappings": {
"properties": {
"hash_code_document":{
"type": "keyword"
}
}
}
或者如果您已经有这样的字段:hash_code_document.keyword,您需要将其用于聚合
我想在 elasticsearch 中查询 returns 重复项,但查询 returns 错误 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
}
是否需要更改映射才能进行查询?
看起来您的字段在映射中定义为“文本”。 Elasticsearch 不允许在此类字段中进行聚合。 您需要将映射中的字段类型更改为“关键字”,例如:
"mappings": {
"properties": {
"hash_code_document":{
"type": "keyword"
}
}
}
或者如果您已经有这样的字段:hash_code_document.keyword,您需要将其用于聚合