Skip to content

Attributes are not included in document payload when updating if names don't match #457

@romeroadrian

Description

@romeroadrian

Attributes are not included in document payload when updating if names don't match.

This is a common scenario, i.e. your model has latitude and longitude attributes where your elasticsearch mapping has a location field.

def as_indexed_json(opts={})
  {location: {latitude: self.latitude, longitude: self.longitude}}
end

In this case, if latitude or longitude change the location field won't be included in the payload (since names don't match).

Relevant code:

https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/lib/elasticsearch/model/indexing.rb#L391

attributes = if respond_to?(:as_indexed_json)
  self.as_indexed_json.select { |k,v| changed_attributes.keys.map(&:to_s).include? k.to_s }
else
  changed_attributes
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions