elasticsearchelasticsearch-2.0

elasticsearch _update_by_query doesn't work


Elasticsearch: 2.3.3

Below are the sequence of my commands

Index a doc

POST test-index/doc
{
  "name":"sahas"
}

Retrieve the doc

GET test-index/_search
{
  "query": {
    "match": {
      "name": "sahas"
    }
  }
}

Update the doc

POST test-index/doc/_update_by_query?name=subramanian
{
  "query": {
    "match": {
      "name": "sahas"
    }
  }
}

Result of update

{
  "took": 9,
  "timed_out": false,
  "total": 1,
  "updated": 1,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": 0,
  "failures": []
}

But when I query the document again, its not updated. Is there anyway to figure out why update is not working here? am i missing something silly?

Appreciate any inputs..


Solution

  • Your update by query didn't modify the source. You need to include a script in order to do so:

    POST test-index/doc/_update_by_query
    {
      "query": {
        "match": {
          "name": "sahas"
        }
      },
      "script": {
        "inline": "ctx._source.name = 'subramanian'"
      }
    }