我正在尝试使用Rails (3.2.8)、Tire和ElasticSearch创建一个自定义映射。
我希望“标题”和“描述”是唯一可搜索/索引的属性.但是,我似乎无法做到这一点:
以下是我的模型:
class BlogPost < ActiveRecord::Base
attr_accessible :title, :description, :attachment, :attachment_thumbnail
include Tire::Model::Search
include Tire::Model::Callbacks
tire.mapping do
indexes :id, :type => 'integer', :index => :not_analyzed, :include_in_all => false
indexes :attachment, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :attachment_thumbnail, :type => 'string', :index => :not_analyzed, :include_in_all => false
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball', boost: 100
end
def self.search(params)
tire.search(load: true, page: params[:page], per_page: 15) do
query do
boolean do
must { string params[:query], default_operator: "AND" } if params[:query].present?
end
end
end
end
end发布于 2014-11-24 20:29:33
您需要将index设置为no
indexes :id, :type => 'integer', :index => :no, :include_in_all => false
indexes :attachment, :type => 'string', :index => :no, :include_in_all => false
indexes :attachment_thumbnail, :type => 'string', :index => :no, :include_in_all => false
indexes :title, analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball', boost: 100使用not_analysed只会防止字段被分解为令牌--它仍将包含在索引中。
有关更多信息,请参见岩心类型。
发布于 2014-12-16 08:21:18
如果更改映射,则应重新编制整个数据的索引。如果是测试数据,则为,则删除索引。创建索引并再次对数据进行索引。我猜您在索引数据后尝试添加:include_in_all => false。
https://stackoverflow.com/questions/27112787
复制相似问题