ElasticSearch:对所有字段使用 match_phrase
ElasticSearch: Using match_phrase for all fields
作为 ElasticSearch 5 的用户,我一直在使用类似这样的东西在所有字段中搜索给定的短语:
GET /my_index/_search
{
"query": {
"match_phrase": {
"_all": "this is a phrase"
}
}
}
现在,_all 字段即将消失,match_phrase 似乎不像 query_string 那样工作,您可以简单地使用类似这样的东西来 运行 搜索所有字段:
"query": {
"query_string": {
"query": "word"
}
}
在不使用 6.0 版中的 _all 字段的情况下对所有字段进行精确短语搜索的替代方法是什么?
我的每个文档都有很多字段,因此在查询中指定所有字段对我来说并不是真正的解决方案。
您可以在 Elasticsearch 文档中找到答案 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html
它说:
Use a custom field and the mapping copy_to parameter
因此,您必须在源中创建自定义字段,并将所有其他字段复制到其中。
作为 ElasticSearch 5 的用户,我一直在使用类似这样的东西在所有字段中搜索给定的短语:
GET /my_index/_search
{
"query": {
"match_phrase": {
"_all": "this is a phrase"
}
}
}
现在,_all 字段即将消失,match_phrase 似乎不像 query_string 那样工作,您可以简单地使用类似这样的东西来 运行 搜索所有字段:
"query": {
"query_string": {
"query": "word"
}
}
在不使用 6.0 版中的 _all 字段的情况下对所有字段进行精确短语搜索的替代方法是什么?
我的每个文档都有很多字段,因此在查询中指定所有字段对我来说并不是真正的解决方案。
您可以在 Elasticsearch 文档中找到答案 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html 它说:
Use a custom field and the mapping copy_to parameter
因此,您必须在源中创建自定义字段,并将所有其他字段复制到其中。