简体   繁体   English

如何在Elasticsearch上使用布尔过滤器进行搜索

[英]How can I search with a boolean filter on elasticsearch

I tried follow the elasticsearch doc to execute my elasticsearch with a filter but couldn't do that. 我尝试按照elasticsearch文档使用过滤器执行我的elasticsearch,但无法做到这一点。 Here is my example: 这是我的示例:

class Post
  def as_indexed_json(options={})
    self.as_json(
      only: [ :id, :title, :published ],
      filter: {
        bool: {
          should: {
            term: { published: true }
          }
        }
      }
    )
  end
end

Do you guys tried this before? 你们以前尝试过吗? Can someone give me a hand on that? 有人可以帮我吗?

Cheers 干杯

Not so sure, but it seems to me that you have an ES syntactic error. 不太确定,但是在我看来,您有ES语法错误。

Could you please past the JSon sent through the ES request? 您能否过去通过ES请求发送的JSon?

I guess that your JSon should look like this: 我猜您的JSon应该看起来像这样:

{
  "filter": {
    "bool": {
      "should": [
        {
          "term": {
            "published": true
          }
        }
      ]
    }
  }
}

But you send this: 但是您发送此:

{
  "only" : [ "valueForId", "valueForTitle", "isPublished" ],
  "filter": {
    "bool": {
      "should": [
        {
          "term": {
            "published": true
          }
        }
      ]
    }
  }
}

Note: to more accurate answers regarding ES, inform the version of the tools you are using (ES 1.0.1 for example) and the data (the content of the JSon) sent to the ES Server, because ES had a quite important syntactic change in the past months and sometimes it is hard to figure out what your class is doing or what you have in your params (:id, :title ...). 注意:要获得有关ES的更准确答案,请告知您正在使用的工具的版本(例如ES 1.0.1)和发送到ES Server的数据(JSon的内容),因为ES在语法上有非常重要的更改在过去的几个月中,有时很难弄清您的课程在做什么或在参数中有什么(:id,:title ...)。

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

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