0

根据文档,我使用这种语法:

self.search(
  query: {
    bool: {
      must: { match: { type: 'user' } },
      must: { match: { status: status } },
      must: { range: { created_at: { from: date_from, to: date_to } } }
    }
  },
  size: 1000
)

我相信它应该寻找所有 3 个条件,但查询忽略了must最后一个条件:

<Elasticsearch::Model::Searching::SearchRequest:0x000000039b2c08 @definition= {:index=>"uusers", :type=>"user", :body=>{:query=>{:bool=>{:must=>{:range=>{:created_at=>{:from=>Mon, 25 Aug 2014, :to=>Thu, 18 May 2017}}}}}, :size=>1000}}

我究竟做错了什么?

4

1 回答 1

2

当您有多个语句时,您必须将其添加到数组中,如下所示:

self.search(
  query: {
    bool: {
      must: [
        { match: { type: 'user' } },
        { match: { status: status } },
        { range: { created_at: { from: date_from, to: date_to } } }
      ]
    }
  },
  size: 1000
)
于 2017-05-18T18:03:44.797 回答