Вложенное сопоставление шин Rails elasticsearch

Я пытаюсь проиндексировать вложенные теги в свою модель продукта. Продукты индексируются хорошо, но не вложенные теги, связанные с продуктом. Как я могу сделать? правильно ли мое отображение?

Product Class

  include Tire::Model::Search
  include Tire::Model::Callbacks

mapping do
    indexes :id, type: 'integer', index: :not_analyzed
    indexes :name, type: 'string', analyzer: 'snowball', boost: 100
    indexes :description, analyzer: 'snowball'
    indexes :price, type: 'float'
    indexes :category, type: 'string'
    indexes :location, type: 'string'
    indexes :online, type: 'boolean'
    indexes :created_at, type: 'date', index: :not_analyzed
    indexes :updated_at, type: 'date', index: :not_analyzed

    indexes :tags do
      indexes :id, type: 'integer', index: :not_analyzed
      indexes :name, type: 'string', analyzer: 'snowball', boost: 100
    end
  end

  def to_indexed_json
    {
      id: id,
      name: name,
      description: description,
      price: price,
      category: category,
      location: location,
      online: online,
      created_at: created_at,
      updated_at: updated_at,
      include: { tags: { only: [:name] } }
    }.to_json
  end

Спасибо!


person Jonnyx Delavilla    schedule 22.07.2013    source источник


Ответы (1)


хорошо, я нашел ответ:

  def to_indexed_json
    {
      name: name,
      description: description,
      price: price,
      category: category,
      location: location,
      online: online,
      created_at: created_at,
      updated_at: updated_at,
      tags: tags
    }.to_json
  end

И нет необходимости включать id, updated_at и created_at в отображение, потому что оно автоматически индексируется. Спасибо Тире!

person Jonnyx Delavilla    schedule 22.07.2013