现在我写
Tire.search INDEX_NAME do
query do
filtered do
query { string term }
filter :or, { missing: { field: :app_id } },
{ terms: { app_id: app_ids } }
end
end
end.results.to_a
最佳答案
返回没有 app_id 或与您的条件匹配的项目听起来像是 or 过滤器的工作 - 我会尝试
filter :or, [
{:not => {:exists => {:field => :app_id}}},
{:terms => {:app_id => app_ids}}
]
关于ruby-on-rails - 如何仅在使用 ElasticSearch 和 Tire 存在时按属性过滤搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259213/