retire icon indicating copy to clipboard operation
retire copied to clipboard

Update index without ActiveRecord callbacks

Open kapso opened this issue 11 years ago • 7 comments

How can I update an index document? I cannot use Tire::Model::Callbacks

kapso avatar Jul 25 '13 02:07 kapso

What is the scenario in which you need to update the index? Is this while the app is running or is this stand alone index sanitization ?

And also, out of curiosity, why can't you use the callbacks ?

mhussain avatar Jul 25 '13 02:07 mhussain

We want to keep DB data in sync with the index hence the update. We have some specific requirements so cannot use callbacks.

kapso avatar Jul 25 '13 02:07 kapso

bundle exec rake environment tire:import CLASS="Model" INDEX="INDEX_NAME" FORCE=true

Should do it

mhussain avatar Jul 25 '13 02:07 mhussain

I figured it out here - https://github.com/karmi/tire/blob/master/examples/tire-dsl.rb#L748

Tire.index 'users' do
  update 'user', "1", doc: { country: 'US' }
end

kapso avatar Jul 25 '13 02:07 kapso

Also is there a DSL to do "script" updates to documents? So something like this (see counter & tags example) - http://www.elasticsearch.org/guide/reference/api/update/

kapso avatar Jul 25 '13 02:07 kapso

Ah ok I see it - https://github.com/karmi/tire/pull/366

kapso avatar Jul 25 '13 03:07 kapso

@kapso The integration test, rather: https://github.com/karmi/tire/blob/master/test/integration/index_update_document_test.rb. So, closing the issue?

karmi avatar Jul 25 '13 07:07 karmi