Elasticsearch QueryStrings:部分匹配NOT查询? [英] Elasticsearch QueryStrings: partially match a NOT query?

查看:508
本文介绍了Elasticsearch QueryStrings:部分匹配NOT查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个使用布尔运算符的搜索字段(如这里所述),我希望他们的行为与我的普通(非布尔运算符)查询相同,由于 prefix_match 。为了说明:搜索 fir ,获取结果,如 fire pit fire ball firm 等。但是,如果我搜索 fire -b ,它仍然返回火球,我认为是错的;我必须搜索火球以排除火球。有没有办法改变这种行为?



为了参考,这是目前发送到ES服务器的查询:



< pre class =snippet-code-js lang-js prettyprint-override> {query:{bool:{should:[{queryString:{fields name,query:fire -b,defaultOperator:OR}},{multi_match:{query:fire -b,type:phrase_prefix字段:[name]}}]}}}

解决方案

查询字符串查询允许通配符。我相信你应该删除多重的。我相信混乱你的结果,只需在每个术语的末尾添加一个通配符,如下所示。如果你想要一些完全匹配,只需不要添加通配符。此外,此查询支持 fuzziness ,默认情况下,它设置为 AUTO ,这再次可能会弄乱您的结果。如果要禁用它,只需将其设置为零。

  {
查询:{
bool:{
should :[
{
queryString:{
fields:[
name
],
query:fire * b *,
defaultOperator:OR
}
}
]
}
}
}


I'm making a search field that will use boolean operators (as described here), and I want them to behave the same as my normal (non-boolean operator) queries, which match on partial strings due to prefix_match. To illustrate: search for fir, get results like fire pit, fire ball, firm, etc. However, if I then search for fire -b, it still returns fire ball, which I consider to be wrong; I have to search for fire -ball to exclude fire ball. Is there a way to change this behaviour?

For reference, this is the query sent to the ES server currently:

{
  "query": {
    "bool": {
      "should": [
        {
          "queryString": {
            "fields": [
              "name"
            ],
            "query": "fire -b",
            "defaultOperator": "OR"
          }
        },
        {
          "multi_match": {
            "query": "fire -b",
            "type": "phrase_prefix",
            "fields": [
              "name"
            ]
          }
        }
      ]
    }
  }
}

解决方案

Query String query allows wildcards. I believe you should remove the multimatch. I believe messes up your results and just add a wildcard at the end of every term like below. If you want exact matches for some, just don't add the wildcard. Moreover this query supports fuzziness which by default is set to AUTO which again could mess up your results. If you want to disable it just set it to zero.

{
  "query": {
    "bool": {
      "should": [
        {
          "queryString": {
            "fields": [
              "name"
            ],
            "query": "fire* -b*",
            "defaultOperator": "OR"
          }
        }
      ]
    }
  }
}

这篇关于Elasticsearch QueryStrings:部分匹配NOT查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆