【问题标题】:Rails elasticsearch tire nested mappingRails elasticsearch轮胎嵌套映射
【发布时间】:2013-07-21 18:35:50
【问题描述】:

我正在尝试将嵌套标签索引到我的产品模型。 产品索引很好,但与产品关联的嵌套标签却没有。 我能怎么做?我的映射正确吗?

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

谢谢!

【问题讨论】:

    标签: ruby-on-rails indexing elasticsearch tire


    【解决方案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,因为它是自动索引的。谢谢轮胎!

    【讨论】:

      猜你喜欢
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 2012-09-24
      • 2014-09-26
      • 2013-09-26
      • 2013-07-23
      • 1970-01-01
      相关资源
      最近更新 更多