gpt4 book ai didi

ruby - 如何在Elasticsearch中结合3个术语?

转载 作者:行者123 更新时间:2023-12-03 01:47:24 25 4
gpt4 key购买 nike

我得到一个搜索,需要对用户组合三个不同的术语:
user_locked? || (user_expired? && !user_granted?)
这是我现在得到的,但是会引发错误消息:

query do
bool do
must { match_all {} }
filter do
bool do
should { term(user_locked: true) }
minimum_should_match { 1 }
end
bool do
filter do
term(user_expired: true)
term(user_granted: false)
end
end
end
end
end

错误信息:
NoMethodError: undefined method 'filter' for #<Elasticsearch::DSL::Search::Filters::Bool
任何想法如何解决这个问题,甚至更好的查询?

最佳答案

尝试这样:

query do
bool do
minimum_should_match 1
should do
term(user_locked: true)
end
should do
bool do
must do
term(user_expired: true)
end
must do
term(user_granted: false)
end
end
end
end
end

更新

根据您的第二条评论,我们需要否定您的条件,即
!(user_locked? || (user_expired? && !user_granted?))
现在等于
!user_locked? && (!user_expired? || user_granted?)
转化为
query do
bool do
must do
term(user_locked: false)
end
must do
bool do
minimum_should_match 1
should do
term(user_expired: false)
end
should do
term(user_granted: true)
end
end
end
end
end

该查询现在将按预期返回带有 user_locked: false, user_expired: false的文档

关于ruby - 如何在Elasticsearch中结合3个术语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42832835/

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