Elasticsearch query_string 通配符语法
Elasticsearch query_string wildcard syntax
显然我可以使用以下通配符查询 ES query_string
:
curl 'http://localhost:9200/my-index/_search?pretty' -d '{
"query": {
"query_string": {
"query": "*:sw?ft"
}
}
}'
此查询是否针对 _all
字段?这使得它等同于:
curl 'http://localhost:9200/my-index/_search?pretty' -d '{
"query": {
"query_string": {
"default_field" : "_all"
"query": "sw?ft"
}
}
}'
如果 _all
在索引中被禁用怎么办?我找不到它的文档。
提前致谢。
首先,这是 query_string 查询的文档:
它对您的两个问题都有答案:
When not explicitly specifying the field to search on in the query
string syntax, the index.query.default_field
will be used to derive
which field to search on. It defaults to _all
field.
So, if _all
field is disabled, it might make sense to change it to
set a different default field.
搜索命令设置为 *:sw?ft
的 query_string
将转换为类似以下内容(假设您的 my-index
索引有一个 my_field
字段,因为示例):
(_field_names:sw?ft | _all:sw?ft | _index:sw?ft | _parent:sw?ft | _uid:sw?ft | _type:sw?ft | _routing:sw?ft | _version:sw?ft | _timestamp:sw?ft | _source:sw?ft | _size:sw?ft | my_field:sw?ft | _id:sw?ft | _ttl:sw?ft | _boost:sw?ft)
因此,:
之前的通配符将被扩展到索引中的所有字段,而不仅仅是您自己定义的字段。小心 query_string
中的通配符,它们会对集群的性能产生不良影响。
因此,为了回答您的问题,*
将扩展为 所有 索引的字段,包括 _all
。如果您只使用 sw?ft
作为搜索字符串,那么默认情况下会使用 _all
.
显然我可以使用以下通配符查询 ES query_string
:
curl 'http://localhost:9200/my-index/_search?pretty' -d '{
"query": {
"query_string": {
"query": "*:sw?ft"
}
}
}'
此查询是否针对 _all
字段?这使得它等同于:
curl 'http://localhost:9200/my-index/_search?pretty' -d '{
"query": {
"query_string": {
"default_field" : "_all"
"query": "sw?ft"
}
}
}'
如果 _all
在索引中被禁用怎么办?我找不到它的文档。
提前致谢。
首先,这是 query_string 查询的文档:
它对您的两个问题都有答案:
When not explicitly specifying the field to search on in the query string syntax, the
index.query.default_field
will be used to derive which field to search on. It defaults to_all
field.So, if
_all
field is disabled, it might make sense to change it to set a different default field.
搜索命令设置为 *:sw?ft
的 query_string
将转换为类似以下内容(假设您的 my-index
索引有一个 my_field
字段,因为示例):
(_field_names:sw?ft | _all:sw?ft | _index:sw?ft | _parent:sw?ft | _uid:sw?ft | _type:sw?ft | _routing:sw?ft | _version:sw?ft | _timestamp:sw?ft | _source:sw?ft | _size:sw?ft | my_field:sw?ft | _id:sw?ft | _ttl:sw?ft | _boost:sw?ft)
因此,:
之前的通配符将被扩展到索引中的所有字段,而不仅仅是您自己定义的字段。小心 query_string
中的通配符,它们会对集群的性能产生不良影响。
因此,为了回答您的问题,*
将扩展为 所有 索引的字段,包括 _all
。如果您只使用 sw?ft
作为搜索字符串,那么默认情况下会使用 _all
.