Sahas
Sahas

Reputation: 3186

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..

Upvotes: 1

Views: 3750

Answers (2)

Ali Karooni
Ali Karooni

Reputation: 1

I had the same problem and it took me 2 days to realize that Elasticsearch uses camel case. So in my case, I changed ctx._source.FirstName = params.newName to ctx._source.firstName = params.newName, even though in my C# it is FirstName.

Upvotes: 0

Val
Val

Reputation: 217314

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'"
  }
}

Upvotes: 3

Related Questions