elastic search|October 11, 2017|1 min read

ElasticSearch - Update a document and change value of a key

ElasticSearch - Update a document and change value of a key

Introduction

I have few documents in the Elastic Search instance. And, due to some change in the code. I had to update the value of few keys in some of the documents.

Solution

Elastic Search has an update method, and we can use it like below:
POST index_name/type_name/<id of document>/_update
{
  "script": "ctx._source.<field> = 'the required value'"
}

Example

In my case, the input is like: ``` { "_index": "jira_create", "_type": "jira_created", "_id": "AV8KVD65tSgrIxXHHggk", "_score": 1, "_source": { "data": { "jiraId": "ABC-1234", "uniqueEntityId": "something was here", "attrs": { "versionId": "fg1pGsEQXLuTdQM1JeIR1CuAvp3K3jQu", "syncIssue": false } }, "createdAt": "2017-10-11T07:26:53.901Z" } } ```

Exact code

``` POST jira_create/jira_created/AV8KVD65tSgrIxXHHggk/_update { "script": "ctx._source.data.uniqueEntityId = 'my new value'" } ```

Thanks for reading.

Related Posts

Resolving Checkmarx issues reported

Resolving Checkmarx issues reported

So, here we are using input variable String[] args without any validation…

How to trim Meta Description tag value generated by Metatag module, to max 160 characters

How to trim Meta Description tag value generated by Metatag module, to max 160 characters

I was using On page optimization of the article pages, and found that meta…

How to solve - Apache Ftp Client library is printing password on console

How to solve - Apache Ftp Client library is printing password on console

The problem comes while using FTPS. When developer uses login method of this…

Java - Union and Intersection of two lists

Java - Union and Intersection of two lists

Suppose you have two lists, and you want Union and Intersection of those two…

A Practical Guide on Understanding Git Best Practices

A Practical Guide on Understanding Git Best Practices

Introduction In this post, we will learn about some of Best practices while…

How to install Perl from Command Line for Automation on Windows and Dockerfile

How to install Perl from Command Line for Automation on Windows and Dockerfile

Introduction Often in automation, we need to install stuff from command line…

Latest Posts

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Introduction In this post we will see following: How to schedule a job on cron…

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

Introduction There are some cases, where I need another git repository while…

How to Fetch Multiple Credentials and Expose them in Environment using Jenkinsfile pipeline

How to Fetch Multiple Credentials and Expose them in Environment using Jenkinsfile pipeline

Introduction In this post, we will see how to fetch multiple credentials and…

Jenkins Pipeline - How to run Automation on Different Environment (Dev/Stage/Prod), with Credentials

Jenkins Pipeline - How to run Automation on Different Environment (Dev/Stage/Prod), with Credentials

Introduction I have an automation script, that I want to run on different…

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Introduction I had to write a CICD system for one of our project. I had to…

Java Log4j Logger - Programmatically Initialize JSON logger with customized keys in json logs

Java Log4j Logger - Programmatically Initialize JSON logger with customized keys in json logs

Introduction Java log4j has many ways to initialize and append the desired…