Update docuement with field name


(Tushar Chevulkar) #1

Is it possible to update any document with a key ? like we do in sql

UPDATE table SET gender='male' WHERE name=dave


(David Pilato) #2

You have the update by query which basically does something similar

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html


(Tushar Chevulkar) #3

I tried this query

{
  "script": {
    "gender": "male"
  },
  "query": {
    "match": {
                    "name_split": "Tim"
                  }
  }
}

But its giving error I don't know what am I doing wrong


(David Pilato) #4

You did not paste the error. But I can imagine what it can be as you are not following what is written in the guide.

POST twitter/_update_by_query
{
  "script": {
    "inline": "ctx._source.likes++",
    "lang": "painless"
  },
  "query": {
    "term": {
      "user": "kimchy"
    }
  }
}

BTW using a pipeline might be good as well as explained in docs:

PUT _ingest/pipeline/set-foo
{
  "description" : "sets foo",
  "processors" : [ {
      "set" : {
        "field": "foo",
        "value": "bar"
      }
  } ]
}
POST twitter/_update_by_query?pipeline=set-foo

But may be you are just beginning with elasticsearch and you may be want to solve something else than updating a field?

I mean that if you want to update a document for which you know the id, just run:

PUT index/type/id
{
  // The full content of your document here, updated
}

(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.