jeudi 29 octobre 2015

Updating multiple documents on nested object change

I am using the elasticsearch-rails and elasticsearch-model gems for my Ruby on Rails app, which is like a question-and-answer site.

I have one index my_index and mappings for question, and answer. In particular, question has a nested object with a user:

"question": {
   "properties": {
      "user": {
         "type": "nested",
         "properties": {
            "created_at": {
               "type": "date",
               "format": "dateOptionalTime"
            },
            "name": {
               "type": "string"
            },
            "id": {
               "type": "long"
            },
            "email": {
               "type": "string"
            }
          }
      }
      ...
   }
}

It's possible for a user to change his name, and I have hooks to update the user in Elasticsearch:

after_commit lambda { __elasticsearch__.index_document},  on: :update

But this isn't updating the appropriate question objects correctly, and I don't know what to pass to the index_document call to make sure it updates all the corresponding questions with the new user name. Does anyone know? It might even help me to see what a RESTful/curl request should look like?

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire