There are 2 questions on elasticsearch

  1. Faced with complexity when changing a document in elasticsearch.

Document structure:

{ service:{ name: name, date: [{time:time, log: log}] } } 

It is necessary to add one more array element to the "date" object. Did this:

 curl -XPOST 'localhost:9200/_index/_doc/_id/_update' -d '{ "script": "ctx._source.service += new_date", "params": { "new_date": {"date": [ {"time": "time_new", "log": "log_new"} ]} } }' 

As a result, I get:

 { service:{ name: name, date: [{time:time, log: log}] date: [{time:time_new, log: log_new}] } } 

And I would like to:

 { service:{ name: name, date: [{time:time, log: log}, {time:time_new, log: log_new}] } } 

Can this be done somehow more carefully, not to create another object?

  1. The second question is tied to the first, how can this be done through python
    ( API Documentation - Elasticsearch ).
    Just starting to deal with this system, do not kick much :-)

Thanks in advance for your help!

    1 answer 1

    1. You need to use scripting . Here is an example from the documentation:

    We can also add it, since it’s a list):

     curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{ "script" : "ctx._source.tags += tag", "params" : { "tag" : "blue" } }' 
    1. And in elasticsearch-py, use the update method with the corresponding parameter values.