Elastic Search equivalent of “Scoping (Scalar Fields)” in sunspot/solr

本小妞迷上赌 提交于 2020-01-06 07:15:35

问题


I'm exploring various options for a search engine for our rails-app/data. I was able to make sunspot/solr work and am currently exploring ElasticSearch as an alternative but couldn't get the same thing(scoping/filtering) to work under ES.

I would like to filter/scope objects as described in the "Scoping" section in 'https://github.com/sunspot/sunspot'.

I have an active record class 'Product'.

class Product < ActiveRecord::Base
...

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.mapping do
    indexes :name, :type => :string
    indexes :categories do
      indexes :id, :type => :integer
    end
  end
end

Once I imported products into ES,

the following query works and gives results

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" } }.results

How do I get products of a particular category given a category id ?

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" }; filter(:term, 'categories.id' => 38) }.results

I'm basically looking for the tire equivalent for the following sunspot call:

Product.search do
  with(:category_ids, 38)
end

with the following in the Product class

searchable :auto_index => true, :auto_remove => true do
  text :name

  integer :category_ids, :multiple => true do
     self.categories.map &:id
  end

end

来源:https://stackoverflow.com/questions/14579392/elastic-search-equivalent-of-scoping-scalar-fields-in-sunspot-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!