adding index for an attribute of jsonb field in elasticsearch rails
I use nested
type to define the jsonb object:
settings index: { number_of_shards: 1 } do mappings dynamic: 'false' do indexes :id, type: 'integer' indexes :user_id, type: 'integer' indexes :name, type: 'text' indexes :data, type: 'nested' do indexes :gender, type: 'text' indexes :age, type: 'integer' end end end
Read here https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html for more information about JSON documents.
If you have dynamic fields in the JSONB objects then you can define the index like this:
settings index: { number_of_shards: 1 } do mappings dynamic: 'false' do indexes :id, type: 'integer' indexes :user_id, type: 'integer' indexes :name, type: 'text' indexes :data, dynamic: 'true' do end end end