0

The official elasticsearch python client

from elasticsearch import Elasticsearch
es = Elasticsearch()
result = es.get(index="test_index", id=1)
print(result)

or

import urllib2
import json
response = urllib2.urlopen('http://localhost:9200/test_index/_search?q=_id:1', )
result = json.loads(response.read())
print(result)

Which of above is best way to query elasticsearch from python?

2
  • Using the official client is generally a better idea than manually calling the API. Why would you use the second one? Commented Feb 17, 2014 at 8:07
  • @Sahand, the official elasticsearch api is released just few months ago (Sep 2013). Until that python applications use elasticsearch with something other than 'official python elasticsearch api'. So i am wondering is there a better way to do this? Commented Feb 17, 2014 at 8:20

1 Answer 1

1

There are a few python clients, the official one is probably going to be the most reliable/consistent and if you looked at the source code it would be doing something similar to your 2nd example. Here are some other Python clients -

  1. elasticsearch
  2. pyelasticsearch
  3. rawes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.