Reputation: 8386
I've an script that calls Elasticsearch with some update_by_query
.
Here I update the item with id=299966
and change the trash flag, trash=0
:
_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=0"
}
}
Then I the item with id=299966
(same item as above) to trash=1
:
_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=1"
}
}
The thing is that after doing this two operations, if I search for the item with id=299966
, I get trash=0
, when it's supposed to be trash=1
as it's the last one executed. I always mantain the order and my own log shows that the one with trash=0
is first executed, and then the one with trash=1
.
Is there any stuff inside the update_by_query
logic that avoids to make two calls? Do I have to wait some seconds or something to make the second update_by_query?
PS: Nervemind those double query
on the codes. It's working ok.
Thanks in advance.
Upvotes: 1
Views: 1076
Reputation: 8386
The solution I found is to use _flush
after every _update
or every _update_by_query
.
myindex/_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=0"
}
}
myindex/_flush
myindex/_update_by_query
{
"query": {
"query": {
"bool": {
"must": [
{
"terms": {
"_id": [
299966
]
}
}
],
"should": [
]
}
}
},
"script": {
"inline": "ctx._source.trash=1"
}
}
Upvotes: 2