簡體   English   中英

如何在elasticsearch-rails中創建實例方法的索引?

[英]How to create index of an instance method in elasticsearch-rails?

我想做的事

https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model

使用這個gem,我想創建用戶模型的索引,包括名為full_name的方法的輸出。 User具有id, first_name, last_name列。

class User
  ...
  def full_name
    first_name + last_name
  end
  ...
end

我做了什么

module UserSearchable
  extend ActiveSupport::Concern

  included do
    include Searchable
    settings index: {
      ...
    }

    mappings do
      indexes :id, type: :integer
      indexes :first_name, type: text
      indexes :last_name, type: text
      indexes :full_name, type: text, as: 'full_name'
    end

    def as_indexed_json(options={})
      as_json(
        methods: [:full_name]
      )
    end
  end
end

我提到了這個問題。 在ElasticSearch中對方法的結果編制索引(Tire + ActiveRecord)

但這不起作用,最終在響應中不包含full_name索引。

我是Elasticsearch和elasticsearch-rails的新手。 我怎樣才能解決這個問題?

抱歉,我只是忘了重新加載代碼中的更改! 並且它不使用as: 'full_name'在當前版本的gem中as: 'full_name'

暫無
暫無

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

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