elasticsearch - 如何在Elasticsearch的术语内使用OR?

标签 elasticsearch

我是Elasticsearch的新手,我需要在查询中添加OR条件的帮助。我目前有这个查询。

{
  :query=>{
    :bool=>{
      :must=>[{
        :query_string=>{
          :default_operator=>"AND", 
          :query=>"*"
        }
      }]
    }
  }, 
  :filter=>{
    :and=>[{
      :term=>{
        :partner_id=>26
      }
    }, 
    {:term=>{
      :is_unpublished=>"false"}
    }]
  }
}

目前,它当前接受26,但是如果我有2个值怎么办?例如。 26和36,如何在OR条件下添加36

如果这是SQL,它将是这样的:
SELECT * FROM table WHERE (partner_id = 26 OR partner_id = 36) AND is_unpublished = false

我尝试了以下方法,但是没有运气:
{:term => {:partner_id => 36}, :or => [:term => {:partner_id => 26}]}

这也没有运气:
{:term => {:or =>[{:partner_id => 26},{:partner_id => 36}]}}

最佳答案

使用“应该”吗?

 "should" : [
    { "term" : { "tag" : "wow" } },
    { "term" : { "tag" : "elasticsearch" } }
  ]

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

关于elasticsearch - 如何在Elasticsearch的术语内使用OR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52811619/

相关文章:

elasticsearch - Elasticsearch渗透器的映射

elasticsearch - Elasticsearch插件修改源文档

ElasticSearch - 仅获取匹配的嵌套对象与搜索响应中的所有顶级字段

autocomplete - Elasticsearch自动完成其余的词

ElasticSearch:如何指定要搜索的特定字段?

elasticsearch - 在 Elasticsearch 中按日期范围获取计数和分组

elasticsearch - Elasticsearch按字段前缀聚合

elasticsearch - Elasticsearch动态类型和not_analyse字段

elasticsearch - 从 HDFS 到 ES 的数据加载需要很长时间

elasticsearch - 在Logstash中过滤jdbc数据