gpt4 book ai didi

ruby-on-rails - ElasticSearch + Rails多个 `must`无法正常工作

转载 作者:行者123 更新时间:2023-12-03 00:55:58 27 4
gpt4 key购买 nike

根据文档,我正在使用以下语法:

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}}

我究竟做错了什么?

最佳答案

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

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

关于ruby-on-rails - ElasticSearch + Rails多个 `must`无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44052659/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com