elasticsearch - Elasticsearch - 匹配短语时避免基于单词和基于模糊的匹配
问题描述
我有一个查询,它搜索短语、单词级别和搜索单词的模糊性。有没有一种方法可以在匹配精确短语时限制单词和模糊匹配?开发的查询是:
PUT test/_doc/1
{
"field1": "this is a test query - query",
"field2": "best rest vest pest"
}
GET test/_search
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "this is a test query",
"type": "phrase",
"slop": "2",
"fields": []
}
},
{
"multi_match": {
"query": "this is a test query",
"analyzer": "whitespace",
"fields": []
}
},
{
"multi_match": {
"query": "this is a test query",
"analyzer": "whitespace",
"fuzziness": "AUTO",
"fields": []
}
}
],
"minimum_should_match": 1
}
},
"highlight": {
"type": "unified",
"fields": {
"*": {}
}
}
}
获得的结果(仅突出显示)是:
“field1”:[“这 是 一个 测试 查询-查询”],“field2”:[“最好的 休息 背心 害虫”]
当“这是一个测试查询”短语匹配时,我不希望突出显示“最佳”、“休息”、“背心”和“害虫”
解决方案
将您的短语搜索放在 a 中must
,并将其他两个条件保留在should
. 查询规划器应该足够聪明,可以为您解决这个问题。
推荐阅读
- python - Python Qt QImage 根据其内容使图像变亮或变暗
- tensorflow - Keras Gpu:配置
- vue.js - 用于大型 html 的 Vue.js v-model
- python - 使用 __getattr__ 导致 TypeError: 'str' object is not callable - Python 2.7
- r - 在数据框中查找逗号并返回行(在 r 中)
- python - 即使选择了 python 3.6,Pycharm 也使用 python 2.7
- vue.js - Nuxt.js:设置 publicPath 导致页面未找到
- excel - 如果条件满足,如何将数据复制到工作表,如果不满足,将数据附加到最后一行?VBA
- machine-learning - 如何在训练深度神经网络时融合一个附加特征?
- c# - 当我在 linq 中使用两个具有相同表名的 dbml 文件时出错