elastic search1 Min Read

ElasticSearch - Update a document and change value of a key

Gorav Singal

October 11, 2017

TL;DR

Use the Elasticsearch _update API with a doc payload to change specific field values in existing documents without reindexing the entire document.

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.

Share

Related Posts

Common used Elastic Search queries

Common used Elastic Search queries

Listing down the commonly used Elastic Search queries. You can get search…

ElasticSearch&#58; Validation Failed&#58; 1&#58; script or doc is missing

ElasticSearch&#58; Validation Failed&#58; 1&#58; script or doc is missing

While dealing with ELastic Search documents, you faced this issue while updating…

How to sync Mongodb data to ElasticSearch by using MongoConnector

How to sync Mongodb data to ElasticSearch by using MongoConnector

Introduction This post is about syncing your mongodo database data to…

How to take Backup from MongoDB and Restore to MongoDB

How to take Backup from MongoDB and Restore to MongoDB

This will take backup of your passed database name, to the passed folder. It…

How to connect Php docker container with Mongo DB docker container

How to connect Php docker container with Mongo DB docker container

Goto your command terminal. Type: This will expose port: 27017 by default. You…

Database Integration — PostgreSQL with Node.js

Database Integration — PostgreSQL with Node.js

Choosing Your PostgreSQL Client Node.js has three main approaches to working…

Latest Posts

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…

Security Ticketing and Incident Response

Security Ticketing and Incident Response

The worst time to figure out your incident response process is during an…

Security Mindset for Engineers — Think Like an Attacker

Security Mindset for Engineers — Think Like an Attacker

Most engineers think about security the way they think about flossing — they…

Secrets Management — Vault, SSM, and Secrets Manager

Secrets Management — Vault, SSM, and Secrets Manager

I’ve watched a production database get wiped because someone committed a root…

Penetration Testing Basics for Developers

Penetration Testing Basics for Developers

Most developers think of penetration testing as something a separate security…

OWASP Top 10 for Cloud Applications

OWASP Top 10 for Cloud Applications

The OWASP Top 10 was written for traditional web applications. But in the cloud…