So in your example https://github.com/elasticsearch/elasticsearch-rails/blob/templates/elasticsearch-rails/lib/rails/templates/searchable.rb#L60 if Authors is updated, how would the original model's index get updated? Running into this issue locally.
To clarify, is it possible to hit the callback method using include Elasticsearch::Model::Callbacks when a touched record was updated?
To further clarify, I have a model Orders which belongs to a Customer. I've added after_touch() { __elasticsearch__.index_document } to my Searchable concern as well. This is my mapping
mapping do
indexes :production_notes, type: 'string', analyzer: 'snowball'
indexes :order_nickname, type: 'string', analyzer: 'keyword'
indexes :visual_id, type: 'integer'
indexes :paid, type: 'boolean'
indexes :orderstatus_id, type: 'integer'
indexes :customer,
type: 'object',
properties: {
first_name: { type: 'string' },
last_name: { type: 'string' },
company: { type: 'string' }
}
end
Is there another method to reindex after touch that I'm not seeing?
Depends on how you define the associations -- have a look e.g. here: https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/examples/activerecord_associations.rb
Aye, this was missing, see this: e8a7f49aea479cd335e3afd62d15f52ab8ed6b6d
Ah ok so include Elasticsearch::Model::Callbacks will know if an associated record is changed when you use touch: true then I'm assuming? Just having trouble getting that working, will have to play with it more.
Ok, what if an Article belongs_to :author?
In that case if you had belongs_to :author, touch: true in Article, would the Article index get updated if Author changed?
@bcackerman So what happens when you try it out?
Specifically I have an index like this:
def as_indexed_json(options={})
hash = self.as_json(
include: {
orderstatus: { only: [:color, :name] },
customer: { methods: [:full_name], only: [:full_name, :company] }
}
)
hash
end
Where an Order belongs to a Customer and an Orderstatus. If I update the order's customer, the index's include isn't updated.
@bcackerman Have you actually tried your suggestion? Why are you asking me what happens?
Oh, I am trying it :) I'm just letting you know it doesn't seem that the Callbacks class works to reindex the record when there's an include in my as_indexed_json method.
Figured it out, thanks!
To follow up on this, associated records that the updated record belongs_to, are not reindexed using just belongs_to :model, touch: true
Most helpful comment
To follow up on this, associated records that the updated record
belongs_to, are not reindexed using justbelongs_to :model, touch: true