Reputation: 5162
Please have a look on below code, Its the normal indexing statement for thinking sphinx
indexes owned_tags.name, :as => :owned_tag_names
has owned_tags.id, :as => :owned_tag_ids, :facet => true
Can any one guide what would be the syntax to have same index in ElasticSearch
?
I tried out.
tire.mapping do
indexes :owned_tag_names, type: 'array', analyzer: :ngram_analyzer, index_name: 'tag'
indexes :owned_tag_ids, type: 'array'
end
def to_indexed_json
{
owned_tag_names: owned_tags.collect(&:name),
owned_tag_ids: owned_tags.collect(&:id)
}.to_json
end
and it is giving me the error:
400 : {"error":"MapperParsingException[mapping [user]]; nested: MapperParsingException[No handler for type [array] declared on field [owned_tag_ids]]; ","status":400}
Upvotes: 0
Views: 994
Reputation: 14419
Use the string
type for definining mapping for arrays, as the documentation suggests:
tire.mapping do
indexes :owned_tag_names, type: 'string', analyzer: :ngram_analyzer, index_name: 'tag'
indexes :owned_tag_ids, type: 'string'
end
Note, that you could define the JSON serialization in the mapping
block with the as
option:
tire.mapping do
indexes :owned_tag_names,
type: 'array',
analyzer: :ngram_analyzer,
index_name: 'tag',
as: proc { owned_tags.collect(&:name) }
indexes :owned_tag_ids,
type: 'array',
as: proc { owned_tags.collect(&:id) }
end
Upvotes: 1