Rails ElasticSearch Model with Fields

I use elasticsearch-rails and mongoid . I have the following simple field mapping:

"title": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } 

My model looks like this:

 class ArticlesEvent include Mongoid::Document include Elasticsearch::Model field :title, type: String attr_accessible :title def as_indexed_json(options={}) as_json(except: [:id, :_id]) end 

Can someone show an example of how to define a rail model with a title.raw field and how to access this field? Since multi-field fields are outdated, it is difficult to find a working example with rails and mangoids.

thanks

+8
ruby-on-rails mongoid elasticsearch
source share
2 answers

It seems like this is still a problem with elasticsearch-rails: https://github.com/elastic/elasticsearch-rails/issues/79

0
source share

You can achieve this by using the following attribute definition in your model:

 attribute :title, String, mapping: { fields: { raw: { type: 'string', index: 'not_analyzed' } } } 
+2
source share

All Articles