简体   繁体   中英

Rails elasticsearch tire nested mapping

I'm trying to index nested tags to my product model. The products indexes well but not the nested tags associated to the product. How can i do? is my mapping correct?

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

Thanks!

ok, i have found the answer:

  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

And no need to include id, updated_at and created_at to the mapping because it's automatically indexed. Thanks Tire!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM