【发布时间】:2021-02-10 01:33:29
【问题描述】:
我们目前有这样的查询:
"query": {
"multi_match": {
"query": "john doe",
analyzer: "whitespace",
type: "most_fields",
}
}
基本上,这会在文档的所有字段中搜索“john”或“doe”。
我们如何在所有字段中准确搜索“john doe”?
这是迄今为止我能做到的最好的:
"query": {
"multi_match": {
"query": "john doe",
"type": "phrase",
}
}
不幸的是,这会在一个字段中搜索“john”和“doe”。它不会在字段中搜索确切的短语“john doe”。
除了将所有字段复制到一个包含所有值的大字段中之外,没有其他办法吗?然后在该字段上运行标准 match_phrase 查询?
这是一个带有虚拟字段名称的索引示例:
{
"my_index": {
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"date1": {
"type": "date"
},
"date2": {
"type": "date"
},
"text1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"text2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"text3": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
样本数据(真实数据是超标准的扁平化字符串)
{
"_index": "myIndex",
"_type": "_doc",
"_id": "013345",
"_score": 7.414526,
"_source": {
"date1": "2017-05220T03:59:59.000Z",
"text1": "Available ",
"text2": "Hello i am john doe",
"text3": "Ministry",
"text4": "Decision",
}
}
提前致谢。
【问题讨论】:
-
你能解释一下吗它不会在字段中搜索确切的短语“john doe”。
-
@ESCoder 查询返回同一字段中包含“john”和“doe”的所有文档,而不是“john doe”的完全匹配
标签: elasticsearch match phrase