我在Rails模型中的Elasticsearch中有以下索引:
mapping do
indexes :id, type: "integer", index: :not_analyzed, include_in_all: false
indexes :number, type: "string"
indexes :title, type: "string"
indexes :description, type: "string"
indexes :creation_date, type: "date", index: :not_analyzed, include_in_all: false
indexes :photographer, type: "integer", index: :not_analyzed, include_in_all: false
indexes :photographer_name, type: "string", as: Proc.new { photographer.name if photographer }
indexes :original_type, type: "integer", index: :not_analyzed, include_in_all: false
indexes :original_type_description, type: "string", as: Proc.new { original_type.description if original_type }
indexes :format_type, type: "integer", index: :not_analyzed, include_in_all: false
indexes :format_type_description, type: "string", as: Proc.new { format_type.description if format_type }
indexes :country, type: "integer", index: :not_analyzed, include_in_all: false
indexes :country_name, type: "string", as: Proc.new { country.name if country }
indexes :state, type: "integer", index: :not_analyzed, include_in_all: false
indexes :state_name, type: "string", as: Proc.new { state.name if state }
indexes :state_region, type: "string", as: Proc.new { state.region if state }
indexes :locality, type: "string"
indexes :license_type, type: "integer", index: :not_analyzed, include_in_all: false
indexes :license_type_description, type: "string", as: Proc.new { license_type.description if license_type }
indexes :model_release_type, type: "integer", index: :not_analyzed, include_in_all: false
indexes :model_release_type_description, type: "string", as: Proc.new { model_release_type.description if model_release_type }
indexes :property_release_type, type: "integer", index: :not_analyzed, include_in_all: false
indexes :property_release_type_description, type: "string", as: Proc.new { property_release_type.description if property_release_type }
indexes :keywords, type: "string", as: Proc.new { keywords.map(&:value) }
end
我需要实现一个autocomplete
字段并找到很多材料,包括这里,教授如何使用Elasticsearch
和Tire执行此操作。但是,它们都只根据索引中的一个字段显示建议。
我需要autocomplete
字段建议在几个字段中找到的字词,例如标题,摄影师和关键字。此外,字段关键字是一个数组,即包含几个单词。