我试图基于一个名为_id
的字段在Elastic中运行regex查询,但我得到了以下错误:
只能在关键字和文本字段上使用通配符查询,而不能在类型为_id的_id上使用。
我试过regexp
{
"query": {
"regexp": {
"_id": {
"value": "test-product-all-user_.*",
"flags" : "ALL",
"max_determinized_states": 10000,
"rewrite": "constant_score"
}
}
}
}
和wildcard
{
"query": {
"wildcard": {
"_id": {
"value": "test-product-all-user_.*",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
但两个人都犯了同样的错误。
这是完全的错误,以防万一:
{ "root_cause":{{“root_cause”:[{ " type ":"query_shard_exception",“原因”:“只能在关键字和文本字段上使用通配符查询-不能在_id上使用_id类型的查询”、"index_uuid":"Cg0zrr6dRZeHJ8Jmvh5HMg“、”索引“:"explore_segments_v3”} ],“类型”:"search_phase_execution_exception",“原因”:“所有碎片失败”,“阶段”:“查询”,“分组”:真,"failed_shards":[{“碎片”:0,“索引”:"explore_segments_v3",“节点”:"-ecTRBmnS2OgjHrrq6GCOw",“原因”:{“类型”:"query_shard_exception",“原因”:“只能对关键字和文本字段使用通配符查询--而不能在_id上使用_id”、"index_uuid":"Cg0zrr6dRZeHJ8Jmvh5HMg“、”索引“:"explore_segments_v3”}、“状态”:400 }
。
发布于 2020-04-23 11:36:59
_id是Elasticsearch中的一种特殊类型,它与其他文本字段不同,它实际上是根据文档的UID“生成”的。
您可以参考此链接获得更多信息,https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html。
根据文档,它只支持有限类型的查询(术语、术语、匹配、query_string、simple_query_string),如果您希望像通配符或regexp那样进行更高级的文本搜索,则需要将ID索引到文档本身上的实际文本字段中。
https://stackoverflow.com/questions/61386139
复制相似问题