如果使用ElasticSearch和Tire存在,则如何按属性过滤搜索?

时间:2013-01-10 13:37:57

标签: ruby-on-rails ruby full-text-search elasticsearch tire

现在我写了

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

1 个答案:

答案 0 :(得分:1)

返回没有app_id的项目或与您的条款匹配的项目听起来像是一个或过滤器的工作 - 我会尝试

filter :or, [
    {:not => {:exists => {:field => :app_id}}},
    {:terms => {:app_id => app_ids}}
  ]