Not clear how to upsert ElasticSearch using python elasticsearch -


look here 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 imagine goal append array or increment previous value (without having document first).

if go official requests, in documentation:

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

i wondering how accomplish appending array (just adding default list). appeared elasticsearch's own examples easier can find python.

i read post before people using python requests doing elasticsearch stuff, , i'm thinking there might point it...

you can put script inside 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 array , appending search it. need enable scripting or can put script in file , put file inside config/scripts folder. syntax might different depending on es version. let me know if not work.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -