ElasticSearchにTireを使用しています。私のアプリケーションには2つのモデルがあります。価格と製品。
Priceクラスを検索し、それが属するProductの:name
属性を検索フィールドに使用しようとしています。今Product 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マッピングは機能しません
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, type: "string", 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
}
}
}
では、製品名のみを使用するようにクエリフィールドを設定する方法を知っている人はいますか?
ありがとうございました。