Looking for Elasticsearch updateByQuery syntax example (Node driver) -


you have elasticsearch index 2 docs:

[   {     "_index": "myindex",     "_type": "mytype",     "_id": "es1472002807930",     "_source": {       "animal": "turtle",       "color": "green",       "weight": 20,     }   },   {     "_index": "myindex",     "_type": "mytype",     "_id": "es1472002809463",     "_source": {       "animal": "bear",       "color": "brown"       "weight": 400,     }   } ] 

later, updated data bear:

{   "color": "pink",   "weight": 500,   "diet": "omnivore", } 

so, want update "color" , "weight" values of bear, , add "diet" key "bear" doc. know there's 1 doc "animal": "bear" (but don't know _id):

using nodejs driver, updatebyquery syntax update "bear" doc these new values?

(note: question has been entirely edited more useful community!)

the other answer missing point since doesn't have script carry out update.

you need this:

post /myindex/mytype/_update_by_query {   "query": {      "term": {       "animal": "bear"     }   },   "script": "ctx._source.color = 'green'" } 

important notes:

  • you need make sure enable dynamic scripting in order work.
  • if using es 2.3 or later, update-by-query feature built-in
  • if using es 1.7.x or former release need install update-by-query plugin
  • if using between es 2.0 , 2.2, don't have way in 1 shot, need in 2 operations.

update

your node.js code should this, you're missing body parameter:

    client.updatebyquery({             index: index,            type: type,            body: {                "query": { "match": { "animal": "bear" } },                "script": { "inline": "ctx._source.color = 'pink'"}            }         }, function(err, res) {              if (err) {                 reporterror(err)              }              cb(err, res)         }     ) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -