theablefew / stretchy

Elasticsearch Models for Rails with an ActiveRecord-like behavior
https://theablefew.github.io/stretchy/#/
MIT License
2 stars 0 forks source link

Use attribute options to generate mapping #77

Closed esmarkowski closed 3 months ago

esmarkowski commented 3 months ago

Mapping definition doesn't work with Elasticsearch::Repository DSL

class Report < StretchyModel
    attribute :title, :text
    attribute :created_by, :keyword
    attribute :body, :text, term_vector: :with_positions_offsets

    index_name 'test_reports'

    mapping dynamic: 'strict' do
        attribute_mappings[:properties].each_pair do |attr, options|
            indexes attr, *options
        end
    end
end
Report.mappings
=> #<Elasticsearch::Model::Indexing::Mappings:0x00000001287b81c0 @mapping={}, @options={}, @type=nil> 

Even setting it directly

Report..mapping(dynamic: 'strict') { indexes :foo, type: 'long' }
 => #<Elasticsearch::Model::Indexing::Mappings:0x00000001287b81c0 @mapping={}, @options={}, @type=nil>