I'm using elasticsearch-rails and mongoid I have the following simple mapping with fields:
"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 anyone show an example how to define the rails model with the title.raw field, and how to access that field? Since the multi fields have been deprecated it's hard to find a working example with rails and mongoid.
Thanks
You should be able to achieve this with the following attribute definition in your model:
attribute :title, String, mapping: {
fields: {
raw: { type: 'string', index: 'not_analyzed' }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With