【问题标题】:How to filter search by attribute only if it exists using ElasticSearch and Tire?仅当使用 ElasticSearch 和轮胎存在时,如何按属性过滤搜索?
【发布时间】:2012-12-24 21:59:54
【问题描述】:

现在我写了

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 您的解决方案比我的missing 过滤器有什么优势吗? filter :or, { missing: { field: :app_id } }
    • 别这么想,虽然我写帖子时你缺少的东西并不存在
    猜你喜欢
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2013-03-03
    相关资源
    最近更新 更多