我在 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
和轮胎来做到这一点。但是,它们都显示仅基于索引中的一个字段的建议。
我需要该autocomplete
字段建议在多个字段中找到的术语,例如标题、摄影师和关键字。此外,字段关键字是一个数组,即包含多个单词。