简体   繁体   English

Elasticsearch中具有匹配短语前缀的“ OR”过滤器

[英]“OR” filter with match phrase prefix in Elasticsearch

I would like to do an Elasticsearch query wherein i want to do an OR filter 我想做一个Elasticsearch查询,其中我想做一个OR过滤器

imagine i have this kind of documents 想象我有这种文件

[ {name : "John Doe"}, {name :"Jane Doe"}, {name:"Steve Doe"} ]

A query that does the same thing with this SQL Query 使用此SQL查询执行相同操作的查询

SELECT * from table WHERE name LIKE 'Ja%' OR name LIKE 'Jo%'

Right now i'm using elasticsearch's match_phrase_prefix for the LIKE but i'm quite stuck with the OR. 现在,我对LIKE使用elasticsearch的match_phrase_prefix,但我对OR还是很固定。

Thanks 谢谢

You can use bool should query for implementing the OR operation. 您可以使用bool should查询来实现OR操作。 You can actually make use of prefix query instead of match_phrase_prefix for what you've described. 您实际上可以使用prefix查询来代替您所描述的内容match_phrase_prefix Anyways, if you still find use case for a match_phrase_prefix query just replace the prefix query in the request below with match_phrase_prefix query. 无论如何,如果仍然找到match_phrase_prefix查询的用例,只需将下面请求中的prefix查询替换为match_phrase_prefix查询即可。

{
  "query": {
    "bool": {
      "should": [
        {
          "prefix": {
            "name": {
              "value": "ja"
            }
          }
        },
        {
          "prefix": {
            "name": {
              "value": "jo"
            }
          }
        }
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM