簡體   English   中英

Rails Elasticsearch輪胎嵌套映射

[英]Rails elasticsearch tire nested mapping

我正在嘗試將嵌套標簽索引到我的產品模型中。 產品索引良好,但與該產品關聯的嵌套標簽索引不好。 我能怎么做? 我的映射正確嗎?

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

謝謝!

好的,我找到了答案:

  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,因為它會自動建立索引。 謝謝輪胎!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM