Help Mapping an Array of ints to Array of Strings to Index on


I am using elastic search in a rails app. I have a model - Posts which and I want to add the tags attribute to my index. The problem is tags are a list of mongoid object id's. So I want to convert them to their string values.

class Post
 include Elasticsearch::Model
 include Elasticsearch::Model::Callbacks

 field :title, :type => String
 field :tags, :type => Array, :default => []

  def as_indexed_json(options = {})
       only: [:title, :body, :tags => ['string', 'string', 'string']]


Basically i want to convert [id1, id2, id3] => [string1, string2, string3] and index on that

(Karel Minarik) #2

Hi, you can just call map on the tags attribute to convert it to their string values.

(system) #3