Need Help to Update Record in Elasticsearch Index


(Rajat) #1

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

'


Update record in elasticsearch
(Rajat) #2

Can anyone please help?


(David Pilato) #3

Please format your code, logs or configuration files using </> icon as explained in this guide 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:

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


(Rajat) #4

Mate. ,

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


(David Pilato) #5

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 and share the link here.


(Rajat) #6
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"
    }
  }
}
'

(Rajat) #7
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://discourse-cdn-sjc1.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://discourse-cdn-sjc1.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)

(David Pilato) #8

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


(Rajat) #9

Thanks


(Rajat) #10

This did not resolve my issue .


(David Pilato) #11

As I said, share a full example on gist.github.com that reproduces your problem.
From that we can hopefully help.


(Rajat) #12

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

(David Pilato) #13

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