Not clear how to upsert ElasticSearch using python elasticsearch

PascalVKooten

Look here for a similar example:

https://stackoverflow.com/a/33247409/1575066

from elasticsearch import Elasticsearch
es = Elasticsearch("localhost:9200")
es.update(index='test',doc_type='test1',id='1',body={'doc' {'username':'Tom'},'doc_as_upsert':True})

But now imagine the goal is to append to an array or to increment a previous value (without having to get the document first).

If you go with official requests, this is in the documentation:

POST /website/pageviews/1/_update
{
   "script" : "ctx._source.views+=1",
   "upsert": {
       "views": 1
   }
}

I was wondering how to accomplish appending to an array (just simply adding to a default list). It appeared elasticsearch's own examples are easier than anything I can find specifically for Python.

I read a post before about people just using python requests for doing elasticsearch stuff, and I'm thinking there might be a point to it...

ChintanShah25

You can put your script inside the body parameter.

from elasticsearch import Elasticsearch

es = Elasticsearch()

es.update(
    index="test",
    doc_type="test1",
    id="1",
    body={"script": "ctx._source.tags+=new_tag",
          "params": {
             "new_tag" : "search"
            }
          }
    )

More on update api

Here tags is an array and I am appending search to it. Also you need to enable scripting for this or you can put script in a file and put that file inside config/scripts folder. Syntax might be different depending on ES version. Let me know if it does not work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to upsert into elasticsearch in spark?

From Java

Elasticsearch : How to delete an Index using python

From Dev

Using ElasticSearch's script_upsert to create a document

From Dev

Using ElasticSearch's script_upsert to create a document

From Dev

How do I properly construct a query using the elasticsearch python API?

From Dev

How to get health of an elasticsearch cluster using python API?

From Dev

How to store key-value pairs in an elasticsearch index using python

From Dev

How do I properly construct a query using the elasticsearch python API?

From Dev

How to store key-value pairs in an elasticsearch index using python

From Dev

Clear all deleted data in Elasticsearch

From Dev

How to integrate elasticsearch with rails application specifically using "Elasticsearch" gem

From Dev

elasticsearch create or update document using python

From Dev

Connecting to AWS Elasticsearch instance using Python

From Dev

aggregate a field in elasticsearch-dsl using python

From Dev

How to compute custom metrics using Elasticsearch + Kibana?

From Dev

How to Synchronize the DB from Index Using Elasticsearch

From Dev

How to bulk insert Json using NEST elasticsearch?

From Dev

how to analyze text in elasticsearch using java api?

From Dev

How to update a document using elasticsearch-py?

From Dev

how cluster failover works in ElasticSearch using NEST

From Dev

Elasticsearch 2.1: how to delete by query using curl

From Dev

How to sort by _doc using elasticsearch java client

From Dev

How to return all the results in Elasticsearch using Java?

From Dev

How to send an ArrayList into ElasticSearch using BulkRequest?

From Dev

How to bulk insert Json using NEST elasticsearch?

From Dev

How to execute RemoveAliasMapping in ElasticSearch using JEST

From Dev

How to install elasticsearch as a service using brew

From Dev

how to sort elasticsearch results using jest

From Dev

How to search terms with wildcard in elasticsearch using querystringquery

Related Related

  1. 1

    How to upsert into elasticsearch in spark?

  2. 2

    Elasticsearch : How to delete an Index using python

  3. 3

    Using ElasticSearch's script_upsert to create a document

  4. 4

    Using ElasticSearch's script_upsert to create a document

  5. 5

    How do I properly construct a query using the elasticsearch python API?

  6. 6

    How to get health of an elasticsearch cluster using python API?

  7. 7

    How to store key-value pairs in an elasticsearch index using python

  8. 8

    How do I properly construct a query using the elasticsearch python API?

  9. 9

    How to store key-value pairs in an elasticsearch index using python

  10. 10

    Clear all deleted data in Elasticsearch

  11. 11

    How to integrate elasticsearch with rails application specifically using "Elasticsearch" gem

  12. 12

    elasticsearch create or update document using python

  13. 13

    Connecting to AWS Elasticsearch instance using Python

  14. 14

    aggregate a field in elasticsearch-dsl using python

  15. 15

    How to compute custom metrics using Elasticsearch + Kibana?

  16. 16

    How to Synchronize the DB from Index Using Elasticsearch

  17. 17

    How to bulk insert Json using NEST elasticsearch?

  18. 18

    how to analyze text in elasticsearch using java api?

  19. 19

    How to update a document using elasticsearch-py?

  20. 20

    how cluster failover works in ElasticSearch using NEST

  21. 21

    Elasticsearch 2.1: how to delete by query using curl

  22. 22

    How to sort by _doc using elasticsearch java client

  23. 23

    How to return all the results in Elasticsearch using Java?

  24. 24

    How to send an ArrayList into ElasticSearch using BulkRequest?

  25. 25

    How to bulk insert Json using NEST elasticsearch?

  26. 26

    How to execute RemoveAliasMapping in ElasticSearch using JEST

  27. 27

    How to install elasticsearch as a service using brew

  28. 28

    how to sort elasticsearch results using jest

  29. 29

    How to search terms with wildcard in elasticsearch using querystringquery

HotTag

Archive