Elasticsearch with python

(Aditya Patel) #1

Currently i am trying to use python to input values in Elasticsearch. The library i am using is: https://github.com/elastic/elasticsearch-py

I am facing issues in updating a field in an already existing id. Is there a different python lib , i should use or this is the standard one which everybody uses.

(Magnus Bäck) #2

That's the official Python client so it should work just fine. If go into a bit more details about the problems you're having I'm sure someone can help out.

(Aditya Patel) #3

I am facing issues in updating few fields of already exisiting id's via python into elasticsearch

(Magnus Bäck) #4

Yes, you said that. But what, specifically, is the issue? What does your code look like? What results do you get? What did you expect to get?

(Aditya Patel) #5

Thanks for the reply.

Suppose following is my code:

from elasticsearch import Elasticsearch

es = Elasticsearch()

WRITE TO ES Test application

doc = {
'user': 'adityap_test',
'message': 'Testing testing222',
'postDate': datetime(2013, 01, 06, 10, 25, 10)
res = es.index(index="index_p", doc_type='table_p', id=1, body=doc)

This code would store my data in index -> index_p and doc->table_p and id -> 1

Now if i want to update my "Message" field by eg.: Testing testing333. I can use the same command and replace the id completely with new fields. But is there an update command as there is "index" command ?

(Magnus Bäck) #6

As documented, index() can be used to create documents as well as update existing documents. You should set the version parameter to the version that the update is based on (i.e. the current version, as far as you know).

I don't believe it's possible to update individual fields of documents, so if you don't have the full document you should fetch it first, apply your changes, then post back.

(Aditya Patel) #7


(system) #8