Elasticsearch-rails: How to set nested mapping using DSL?

Created on 16 Jan 2015  Â·  4Comments  Â·  Source: elastic/elasticsearch-rails

Hey... I'd like to set a mapping for a field via an activerecord association. I have the indexed JSON:

Thing.last.__elasticsearch__.as_indexed_json
=> {"variation"=>"5%", "notes"=>nil, "family"=>{"name"=>"240Ω Resistor"}}

I'd like to boost family name, how can I do this using the DSL? Current mappings are:

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :variants, analyzer: 'english', index_options: 'offsets'
      indexes :notes, analyzer: 'english', index_options: 'offsets'
      indexes ???, analyzer: 'english', index_options: 'offsets', boost: 1.1
    end
  end

Thanks!

waiting

Most helpful comment

Thank you, @karmi, the nested example works as expected.
But I didn't find anything like that in documentation or in sources - should I create a pull request?

All 4 comments

Hi, first of all, I'd stay away from index time boost as far as I can, and use the boost when querying.

I'm not sure I understand what you call nested mapping -- do you mean the nested type in Elasticsearch sense?

There's an example for Elasticsearch::Model eg. here, https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/test/integration/active_record_associations_test.rb#L108, and the example applications use that as well.

Thanks @karmi — it's the nested syntax I was looking for:

indexes :comments, type: 'nested' do
  indexes :text
  indexes :author
end

Will use this and switch to query boost!

@mcoms Closing the issue, hope it helped!

Thank you, @karmi, the nested example works as expected.
But I didn't find anything like that in documentation or in sources - should I create a pull request?

Was this page helpful?
0 / 5 - 0 ratings