last day (14 days later) » 

6:27 AM
1
A: How to update multiple documents that match a query in elasticsearch

ValYou could use the update by query plugin in order to do just that. The idea is to select all document without a category and whose url matches a certain string and add the category you wish. curl -XPOST 'localhost:9200/webproxylog/_update_by_query' -d ' { "query": { "filtered": { "fi...

 
I edited the q about that. I already tried this before, but documents not updated..
 
Val
The first term in your update-by-query should be on field heroname not url. The screenshots don't seem to have anything in common with the initial documents in your question.
 
I change it already sorry,
 
Val
is your heroname field analyzed or not? if you add the missing filter to your search query at the top, what do you get?
 
its analyzed, real field data Wrath King and SAND KING but I can get these docs with term:"king"
you mean search query like this; "bool": { "must": [ { "term": { "heroname": "king" } }, { "missing": { "field": "myfield" } } ] }... same result returns this 2 docs
 
Val
6:27 AM
Yes what happens if you run just the query without the script part, i.e. the idea is to figure out the documents matched that would be updated by the script.
Oh wait I see the issue... you just need to post on /dota2/_update_by_query without the /agust part
 
I figured out something, if I run query dota2/agust/_update_by_query/...
it add script add query strings to mapping..
 
Val
Yes, my bad, sorry. you just need to run the POST on /dota2/_update_by_query
not /dota2/agust/_update_by_query
otherwise it creates a document of type "agust" with id "_update_by_query"
now you can just DELETE /dota2/agust/_update_by_query since that's a wrong document
and then simply run
POST /dota2/_update_by_query ...
and that should work
 
6:44 AM
I am afraid but its not.. I cleaned question. I think something wrong with my elasticsearch version or plugin, I expect after query "POST /dota2/_update_by_query .." a result true or false but it adds these strings to mappings
 
Val
Wipe your index and try again.
what do you get when you run this:
curl 'localhost:9200/_cat/plugins?v'
maybe your update by query plugin wasn't installed correctly
or you didn't restart your cluster
 
okey I am on it
I run GET _cat/plugins and result: => Neptune river-twitter 2.6.0 j
Neptune marvel 1.3.1 j/s /_plugin/marvel/
there 2 plugins river-twitter and marvel.. so _update_by_query missing where should I get this to be reliable ?
 
Val
what happens when you run this?

bin/plugin -install com.yakaz.elasticsearch.plugins/elasticsearch-action-updatebyquery
 
6:59 AM
I installed it and run GET _cat/plugins query again result:
Landslide river-twitter 2.6.0 j
Landslide action-updatebyquery NA j
Landslide marvel 1.3.1 j/s /_plugin/marvel/
 
Val
so now you can start ES again
and try to run the _update_by_query again
 
I restart and recreate index and run POST dota2/_update_by_query ...
result : {
"ok": true,
"took": 8,
"total": 2,
"updated": 0,
"indices": [
{
"dota2": {}
}
]
}
at least it didt add these strings to mapping looking fine but documents still same field not added..
Although query result looks true, new field not added to docs, need refresh or etc?
 
Val
7:16 AM
Oh perhaps, you have scripting disabled.
In elasticsearch.yml, you need this:

script.inline: on
script.indexed: on
+ restart ES
 
ITS DONE!!!
mann you are really helpful master I really really grateful to you.. if you don't mind just add your last message to your answer then let me add +50 bounty to this post at least I can do this, you saved me and many suffer like me thank you so much
 
Val
Awesome!!!
Oh, that would be really appreciated !! but you don't need to, only if you really want to :)
 
Yeah I really want to do this, you deserve further more.
1 day for allowed open boundy
 
Val
Thank you Mehmet, it's people like you that make me want to help out :-) Kudos!
no worries you'll do tomorrow
 
7:36 AM
yeah, and let me ask one thing how can I set mappings of this new field. I tried in missing scope of query but u guess.. not work.
"missing": {
"field": "myfield",
"type":"not_analyzed"
}
default type of added field is analyzed.. so I may need change it to not analyzed.
 
Val
7:47 AM
you need to add it to the mapping:
curl -XPUT localhost:9200/dota2/_mapping/agust -d '{"agust":{"properties":{"myfield":{"type":"string","index":"not_analyzed"}}}}'
you need to do it before adding the field, i.e. before running the _update_by_query the first time
 
8:01 AM
I got it. Thank you again,
 
Val
Yup!
 

last day (14 days later) »