Elastyczne wyszukiwanie / opona: jak odwzorować atrybut skojarzenia?

używamOpona do wyszukiwania elastycznego. W mojej aplikacji mam 2 modele; Cena i produkt.

Próbuję przeszukać moją klasę cen i użyć produktu, do którego należy:name atrybut dla pola wyszukiwania. Teraz, gdybym miał produkt o nazwieProduct 1 i wpisz „pro”, „prod” lub „duct”, nie pojawią się żadne wyniki. Ale wpisanie „produkt” lub „Produkt” pokazuje wyniki. Wierzę, że problem tkwi w moim mapowaniu. Spojrzałem na zapytanie i jego:

...localhost:3000/search/results?utf8=%E2%9C%93&query=product

Kiedy myślę, że powinno być:

...localhost:3000/search/results?utf8=%E2%9C%93&query:product=product

Sądząc po tym pytaniu:Mapowanie ElasticSearch nie działa

Nie wiem jak zrobić mojeparams[:query] wziąćproduct.name tylko jednak. Próbowałem użyć:string params[:query], default_field: "product.name" ale to nie zadziałało.

Nie chcę używać_all pole.

Oto mój kod:

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
      }
    }
  }

Czy więc ktoś ma jakieś sugestie lub wie, jak ustawić pole zapytania tylko na nazwę produktu?

Dziękuję Ci.

questionAnswers(2)

yourAnswerToTheQuestion