我正在使用
Tire进行弹性搜索.在我的应用程序中,我有2个模型;价格和产品.
我正在尝试搜索我的Price类并使用它所属的产品:搜索字段的name属性.现在,如果我有一个名为产品1的产品并输入“pro”,“prod”或“duct”,则不会出现任何结果.但输入“product”或“Product”会显示结果.我相信问题在于我的映射.我查看了查询及其:
...localhost:3000/search/results?utf8=%E2%9C%93&query=product
当我认为它应该是:
...localhost:3000/search/results?utf8=%E2%9C%93&query:product=product
从这个问题来看:ElasticSearch mapping doesn’t work
我不知道如何让我的params [:query]只接受product.name.我尝试使用:string params [:query],default_field:“product.name”但是没有用.
我不想使用_all字段.
这是我的代码:
Price.rb
include Tire::Model::Search include Tire::Model::Callbacks def self.search(params) tire.search(load: true,page: params[:page],per_page: 20) do query do boolean do must { string params[:query] } if params[:query].present? must { term :private,false } end end sort do by :date,"desc" by :amount,"asc" end end end def to_indexed_json to_json( include: { product: { only: [:name] } } ) end mapping do indexes :id,type: "integer" indexes :amount,type: "string",index: "not_analyzed" indexes :date,type: "date",index: "not_analyzed" indexes :private,type: "boolean" indexes :product do indexes :name,analyzer: "custom_analyzer" end end settings analysis: { analyzer: { custom_analyzer: { tokenizer: [ "whitespace","lowercase" ],filter: [ "ngram_filter","word_delimiter_filter" ],type: "custom" } },filter: { ngram_filter: { type: "nGram",min_gram: 2,max_gram: 15 } },filter: { word_delimiter_filter: { type: "word_delimiter",generate_word_parts: true,generate_number_parts: true,preserve_original: true,stem_english_possessive: true } } }
那么有没有人有任何建议或知道如何设置查询字段只使用产品名称?
谢谢.