# Need Help to Update Record in Elasticsearch Index

**URL:** https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295
**Category:** Elasticsearch
**Created:** [February 20, 2019, 9:43pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295 "2019-02-20T21:43:11Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [February 20, 2019, 9:43pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/1 "2019-02-20T21:43:12Z")

</div>

Hi All. ,

**I am not an expert in Elasticsearch, hence forgive me if this question is very silly . I am trying to update a record in. elastic search but unable to achieve the goal. .**  
**Elastic Version. : 6.6.** \*

Requirement :- To update the field value.  
Field name :- Source  
Current Value. :- %{[beat][hostname]}"

New Value. :- LMSS\_APP\_LOGIN

Update when matching condition

I tried following. :- but no luck.

_curl -X POST "[http://localhost:9200/graylog](http://localhost:9200/graylog)_\*/_update\_by\_query" -H 'Content-Type: application/json' -d'_  
_{_  
\_ "script": {\_  
\_ "inline":\_  
\_ "ctx._source.data.oldValues.source=ctx.source.data.currentValues.source;  
\_ ctx.source.data.currentValues.source=params.newState.source;",  
\_ "params": {_  
\_ "newState": {"source": "LMSS\_APP\_LOGIN" }\_  
\_ }\_  
\_ },\_  
\_ "query": {\_  
\_ "term": {\_  
\_ "environment": "LMSS"\_  
\_ }\_  
\_ }\_  
_}_  
'  
}

Thrown following error.

**{"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4ffc89c7; line: 5, column: 79]"}],"type":"json\_parse\_exception","reason":"Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4ffc89c7; line: 5, column: 79]"},"status":500}[root@rootlm01 scripts]#**  
**[root@rootlm01 scripts]#**

'

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [February 28, 2019, 9:43pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/2 "2019-02-28T21:43:46Z")

</div>

Can anyone please help?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 1, 2019, 1:39am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/3 "2019-03-01T01:39:41Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 1, 2019, 4:30am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/4 "2019-03-01T04:30:26Z")

</div>

Mate. ,

Unfortunately could not edit it successfully I Any help would be a appreciated. .

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 2, 2019, 11:47am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/5 "2019-03-02T11:47:31Z")

</div>

> Unfortunately could not edit it successfully

What did not work?  
May be try again from scratch.

Using the markdown format as I mentioned like:

Or use markdown style like:

````
```
curl -X POST "http://localhost:9200/graylog*/update_by_query" -H 'Content-Type: application/json' -d'
{
  // Your content
}
```

````

This produces:

```
curl -X POST "http://localhost:9200/graylog*/update_by_query" -H 'Content-Type: application/json' -d'
{
  // Your content
}

```

As you can see this a well formatted text.  
If we can copy and paste your code it might be easier to tell you where the problem is coming from.

If you still don't succeed, you can also copy/paste your code on [gist.github.com](http://gist.github.com) and share the link here.

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 3, 2019, 9:54pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/6 "2019-03-03T21:54:06Z")

</div>

```
curl -X POST "http://192.168. **** :9200/graylog_*/_update_by_query" -H 'Content-Type: application/json' -d'
{
  "script": {
    "source": "ctx._source.source=LMSS_APP_LOGIN",
    "lang": "painless"
  },
  "query": {
    "term": {
      "environment": "LMSS"
    }
  }
}
'
```

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 3, 2019, 9:55pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/7 "2019-03-03T21:55:10Z")

</div>

```
Hi All. ,

**I am not an expert in Elasticsearch, hence forgive me if this question is very silly . I am trying to update a record in. elastic search but unable to achieve the goal. .**
 **Elastic Version. : 6.6.** *

Requirement :- To update the field value.
Field name :- Source
Current Value. :- %{[beat][hostname]}"

New Value. :- LMSS_APP_LOGIN

Update when matching condition

I tried following. :- but no luck.

*curl -X POST "http://localhost:9200/graylog* */ *update_by_query" -H 'Content-Type: application/json' -d'*
*{*
_ "script": {_
_ "inline":_
_ "ctx. <em>source.data.oldValues.source=ctx. *source.data.currentValues.source;*
_ ctx. *source.data.currentValues.source=params.newState.source;",*
_ "params": {</em>
_ "newState": {"source": "LMSS_APP_LOGIN" }_
_ }_
_ },_
_ "query": {_
_ "term": {_
_ "environment": "LMSS"_
_ }_
_ }_
*}*
'
}

Thrown following error.

**{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4ffc89c7; line: 5, column: 79]"}],"type":"json_parse_exception","reason":"Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4ffc89c7; line: 5, column: 79]"},"status":500}[root@rootlm01 scripts]#**
**[root@rootlm01 scripts]#**

'

Reply

* [Update record in elasticsearch](https://discuss.elastic.co/t/update-record-in-elasticsearch/170410/2)

* #### created

![|20x20](https://avatars.discourse.org/v2/letter/r/4af34b/40.png)11d

* [
#### last reply
![|20x20](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/40/12_2.png)1d
](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/5)
* 4

#### replies

* 57

#### views

* 2

#### users

* 2

#### links

* ![|32x32](https://avatars.discourse.org/v2/letter/r/4af34b/64.png)3

![|32x32](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/64/12_2.png)

8 DAYS LATER

[![|45x45](https://avatars.discourse.org/v2/letter/r/4af34b/90.png)](https://discuss.elastic.co/u/rajatdey80)

[rajatdey80](https://discuss.elastic.co/u/rajatdey80)[Rajat](https://discuss.elastic.co/u/rajatdey80)

[3d](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/2?u=rajatdey80)
```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 3, 2019, 10:14pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/8 "2019-03-03T22:14:47Z")

</div>

I don't know but it sounds like you have a bad character in your JSon: `CTRL-CHAR, code 10`

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 4, 2019, 1:37am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/9 "2019-03-04T01:37:42Z")

</div>

Thanks

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 8, 2019, 12:14am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/10 "2019-03-08T00:14:16Z")

</div>

This did not resolve my issue .

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 8, 2019, 4:44am UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/11 "2019-03-08T04:44:55Z")

</div>

As I said, share a full example on [gist.github.com](http://gist.github.com) that reproduces your problem.  
From that we can hopefully help.

---

<div class="post-metadata">

### Author: ![rajatdey80](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rajatdey80](https://discuss.elastic.co/u/rajatdey80)
#### Post date: [March 14, 2019, 9:29pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/12 "2019-03-14T21:29:11Z")

</div>

T hanks Mate .  
Can you please post me a simple example .

```
If I want to update following as per oracle I am asking this question :- 

Update employee set amp_id=10 where tmp-id=100 and tmp_name=smith ; 

Rajat
```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 14, 2019, 10:03pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/13 "2019-03-14T22:03:16Z")

</div>

Look at [https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docs-update-by-query.html)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 11, 2019, 10:03pm UTC](https://discuss.elastic.co/t/need-help-to-update-record-in-elasticsearch-index/169295/14 "2019-04-11T22:03:16Z")

</div>

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