yakaz / elasticsearch-action-updatebyquery

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

The number of updated documents is not equal the total of documents that match query #43

Closed tuan3w closed 9 years ago

tuan3w commented 9 years ago

Thank you for creating this useful plugin. I use this bellow query to update documents that match queries

POST http://host:9200/webdata/doc/_update_by_query?search_type=scan
{
    "query": {
        "match_phrase": {
            "token": "my phrase query"
        }
    },
    "script": "ctx._source.bn=[\"bds\"]"
}

but the result when i receive is very odd

{
  "indices": [
    {
      "webdata": {}
    }
  ],
  "ok": true,
  "took": 19118,
  "total": 92908,
  "updated": 10995
}

As can see from return json, the number of updated documents is much smaller than the total documents that match query. At first, I think there maybe some shards in elastic cluser that got problems, but when I check, everything is ok. I use elasticsearch v1.7.1 and action-updatebyquery v2.6.0 Thanks for your help.

ofavre commented 9 years ago

This means that 92908 documents match the query, and the script has been evaluated against all of them, but only 10995 finally got updated because the script induced a change in the document source. So 81913 documents already had the value ["bds"] in the field bn.

Feel free to reopen if you can prove and reproduce an issue with a small curl recreation.

tuan3w commented 9 years ago

Hi @ofavre. I count number of documents that match query that has value "bds" in the field bn and the result is 10995 documents not 92908. My query:

GET http://host:9200/webdata/doc/_count
{
    "query": {
        "match_phrase": {
            "bn": "bds"
        }
    }
}

And here is the result:

{
  "_shards": {
    "failed": 0,
    "successful": 17,
    "total": 17
  },
  "count": 10995
}