{"action":"created","issue":{"url":"https://api.github.com/repos/toptal/chewy/issues/295","labels_url":"https://api.github.com/repos/toptal/chewy/issues/295/labels{/name}","comments_url":"https://api.github.com/repos/toptal/chewy/issues/295/comments","events_url":"https://api.github.com/repos/toptal/chewy/issues/295/events","html_url":"https://github.com/toptal/chewy/issues/295","id":121215140,"number":295,"title":"Need help for update_index","user":{"login":"nyddogghr","id":3328219,"avatar_url":"https://avatars.githubusercontent.com/u/3328219?v=3","gravatar_id":"","url":"https://api.github.com/users/nyddogghr","html_url":"https://github.com/nyddogghr","followers_url":"https://api.github.com/users/nyddogghr/followers","following_url":"https://api.github.com/users/nyddogghr/following{/other_user}","gists_url":"https://api.github.com/users/nyddogghr/gists{/gist_id}","starred_url":"https://api.github.com/users/nyddogghr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyddogghr/subscriptions","organizations_url":"https://api.github.com/users/nyddogghr/orgs","repos_url":"https://api.github.com/users/nyddogghr/repos","events_url":"https://api.github.com/users/nyddogghr/events{/privacy}","received_events_url":"https://api.github.com/users/nyddogghr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-09T11:22:18Z","updated_at":"2015-12-09T12:46:57Z","closed_at":null,"body":"Hi,\r\n\r\nI'm having a bit of trouble with the updates on index. I have different cases for which I would like to get help.\r\n\r\nFirst one: I have a `Media` model, indexed in my `SearchIndex`. I have added `update_index search#media, :self` in this model. When creating a new media, it is correctly indexed, but nothing happens when it is destroyed.\r\n\r\nSecond one, linked to globalization: I've looked at another issue you've answered to, and I chose to use this for the name translations:\r\n```\r\n field :name_translations, type: 'object'\r\n template 'name_translations.*', type: 'string', index: 'analyzed'\r\n```\r\nHow can I update my media when i change the name, as it is in fact not a `media` that is updated, but a `media_translation` ?\r\n\r\nFinally, I have participants linked to medias through mediographies. A media can have several participants, and a participants several medias. How can I make the index update for a media when I edit a participant ? And how can I update the mediographies of a media ?\r\n\r\nHere are the files (models are shortened) with what I've tried so far:\r\nSearchIndex:\r\n```\r\nclass SearchIndex < Chewy::Index\r\n\r\n  define_type Media.includes(:mediographies, :containers) do\r\n    field :name_translations, type: 'object'\r\n    template 'name_translations.*', type: 'string', index: 'analyzed'\r\n    field :description_translations, type: 'object'\r\n    template 'description_translations.*', type: 'string', index: 'analyzed'\r\n    field :media_type_id\r\n    field :mediographies, value: ->(media) { media.mediographies.map(&:name) }\r\n    field :containers do\r\n      field :name, :description\r\n    end\r\n  end\r\n\r\n  define_type Container.includes(:mediographies, :medias) do\r\n    field :name, :description\r\n    field :mediographies, value: ->(container) { container.mediographies.map(&:name) }\r\n    field :medias do\r\n      field :name_translations, type: 'object'\r\n      template 'name_translations.*', type: 'string', index: 'analyzed'\r\n      field :description_translations, type: 'object'\r\n      template 'description_translations.*', type: 'string', index: 'analyzed'\r\n      field :media_type_id\r\n    end\r\n  end\r\n\r\n  define_type Participant.includes(:mediographies) do\r\n    field :name\r\n    field :mediographies do\r\n      field :media do\r\n        field :name_translations, type: 'object'\r\n        template 'name_translations.*', type: 'string', index: 'analyzed'\r\n        field :description_translations, type: 'object'\r\n        template 'description_translations.*', type: 'string', index: 'analyzed'\r\n        field :media_type_id\r\n      end\r\n      field :container do\r\n        field :name, :description\r\n      end\r\n    end\r\n  end\r\n\r\nend\r\n```\r\nMedia:\r\n```\r\nclass Media < ActiveRecord::Base\r\n  translates :name, :description\r\n  Media::Translation.attr_accessible(\"name\", \"description\", \"locale\", as: :renderer)\r\n  update_index('search#media', :self)\r\n  update_index('search#container', :medias)\r\n  update_index('search#participants', :mediographies)\r\n  has_many :mediographies, :dependent => :destroy\r\nend\r\n```\r\nContainer:\r\n```\r\nclass Container < ActiveRecord::Base\r\n  update_index('search#container', :self)\r\n  update_index('search#media', :containers)\r\n  update_index('search#participant', :mediographies)\r\n  has_many :mediographies, :dependent => :destroy\r\nend\r\n```\r\nMediography:\r\n```\r\nclass Mediography < ActiveRecord::Base\r\n  update_index('search#media', :mediographies)\r\n  update_index('search#container', :mediographies)\r\n  update_index('search#participant', :mediographies\r\n  belongs_to :participant\r\n  belongs_to :media\r\n  belongs_to :container\r\nend\r\n```\r\nParticipant:\r\n```\r\nclass Participant < ActiveRecord::Base\r\n update_index('search#participant', :self)\r\n has_many :mediographies, :dependent => :destroy\r\nend\r\n```\r\n\r\nCurrently, the only solution I could see would be to use `SearchIndex::Model.import id` to reimport the models. But I fear it is to heavy.\r\n\r\nIf you could help me get the indexes updated for every actions on these models, it would be very kind.\r\nThanks"},"comment":{"url":"https://api.github.com/repos/toptal/chewy/issues/comments/163217237","html_url":"https://github.com/toptal/chewy/issues/295#issuecomment-163217237","issue_url":"https://api.github.com/repos/toptal/chewy/issues/295","id":163217237,"user":{"login":"nyddogghr","id":3328219,"avatar_url":"https://avatars.githubusercontent.com/u/3328219?v=3","gravatar_id":"","url":"https://api.github.com/users/nyddogghr","html_url":"https://github.com/nyddogghr","followers_url":"https://api.github.com/users/nyddogghr/followers","following_url":"https://api.github.com/users/nyddogghr/following{/other_user}","gists_url":"https://api.github.com/users/nyddogghr/gists{/gist_id}","starred_url":"https://api.github.com/users/nyddogghr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyddogghr/subscriptions","organizations_url":"https://api.github.com/users/nyddogghr/orgs","repos_url":"https://api.github.com/users/nyddogghr/repos","events_url":"https://api.github.com/users/nyddogghr/events{/privacy}","received_events_url":"https://api.github.com/users/nyddogghr/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T12:46:57Z","updated_at":"2015-12-09T12:46:57Z","body":"Thanks for the quick answer. I try this and come back if I still have issues."}}