yakaz / elasticsearch-action-updatebyquery

ElasticSearch Update By Query action plugin
113 stars 24 forks source link

Update object #34

Closed mahadoang closed 9 years ago

mahadoang commented 9 years ago

PUT authors/book/1 { "name": "Revelation Space1", "genre": "scifi1", "publisher": "penguin1", "author":[ {"author_id":1001,"author_name":"mahadoang"}, {"author_id":1002,"author_name":"bugping"} ] }

PUT authors/book/2 { "name": "Revelation Space2", "genre": "scifi2", "publisher": "penguin2", "author":[ {"author_id":1001,"author_name":"mahadoang"}, {"author_id":1003,"author_name":"bugping3"} ] }

PUT authors/book/3 { "name": "Revelation Space3", "genre": "scifi3", "publisher": "penguin3", "author":[ {"author_id":1001,"author_name":"mahadoang"} ] }

GET authors/book/_search { "query": { "query_string": { "default_field": "author.author_id", "query": 1001 } } }

i want update author.author_name form "mahadoang" to "somechai" where author.author_id = 1001

///////////////////// update //////////////// POST authors/_update_by_query { "query": { "query_string": { "default_field": "author.author_id", "query": 1001 } }, "script" : "ctx._source.author.author_name = author_name", "params" : { "author_name" : "somechai" } }

not update help me. Thank you.

ofavre commented 9 years ago

As you use a dynamic script, make sure to enable them explicitly in the conf, as it is disabled by default since ElasticSearch 1.2.0. Simply add script.disable_dynamic: false to your elasticsearch.yml configuration file.

Feel free to reopen the issue if this does not solve your problem.

mahadoang commented 9 years ago

Thank you update success.

but cannot update author_name only

"script" : "ctx._source.author += author", "params" : { "author" : {"author_id":1001,"author_name":"somchai"} }

result : "author": [ { "author_id": 1001, "author_name": "mahadoang" }, { "author_id": 1003, "author_name": "bugping3" }, { "author_name": "somchai", "author_id": 1001 } ]

i want update author.author_name form "mahadoang" to "somechai" where author.author_id = 1001 not append help me.

ofavre commented 9 years ago

You would need to iterate the ctx._source.author array yourself in the script for that. Just look how this could be done in groovy. Try this:

for (a in ctx._source.author) {
  if (a.author_id == author.author_id) {
    a = author // or a.author_name = author.author_name
  }
}
mahadoang commented 9 years ago

Thank you very much.