【问题标题】:Filter ElasticSearch results by Mongo _id按 Mongo _id 过滤 ElasticSearch 结果
【发布时间】:2012-12-17 20:38:58
【问题描述】:

我目前正在使用 Mongoid/MongoDB 作为我的数据库与轮胎/弹性搜索。我想根据_id 的数组过滤我的结果。这是一些类似于我正在尝试的伪代码:

search = Tire::Search::Search.new()
search.filter :terms, :_id => [array_of_ids]

当我换出:_id 属性并尝试使用另一个索引属性时,它工作正常。但是,对于 :_id,它不会返回任何结果。

【问题讨论】:

    标签: ruby-on-rails mongoid elasticsearch tire


    【解决方案1】:

    原来你不能通过:_id:id 进行过滤。这是轮胎特定的还是 ElasticSearch 特定的,我不确定。

    在我的轮胎自定义映射中,我继续添加了一个重复字段作为别名。更多伪代码:

    tire.mapping do
      indexes :id,         :index    => :not_analyzed
      indexes :content_id, :analyzer => :keyword,
                           :as       => "_id"
      ...
    end
    

    重要的部分是indexes :content_id, :as => "_id"。从那时起,我使用:content_id 进行过滤。

    【讨论】:

    猜你喜欢
    • 2021-10-15
    • 2015-10-06
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    相关资源
    最近更新 更多