0

I'm currently using Mongoid/MongoDB for my database with Tire/ElasticSearch. I want to filter my results based on an array of _id's. Here is some pseudo-code similar to what I'm attempting:

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

When I swap out the :_id attribute and attempt to use another indexed attribute, it works fine. However, with :_id, it returns no results.

Nick
  • 9,493
  • 8
  • 43
  • 66

1 Answers1

0

Turns out you're not allowed to filter by :_id or :id. Whether this is Tire specific or ElasticSearch specific, I'm unsure.

In my Tire custom mapping, I've gone ahead and added a duplicate field as sort of an alias. More psuedo-code:

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

The important part being indexes :content_id, :as => "_id". From that point, I filtered using :content_id.

Nick
  • 9,493
  • 8
  • 43
  • 66
  • Please try the http://www.elasticsearch.org/guide/reference/query-dsl/ids-filter.html filter. – karmi Dec 22 '12 at 09:59