Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is better to query elasticsearch from python?

There are to libraries to do this pyes and pyelasticsearch. The pyelasticsearch website looks good, and pyes take an other approach but also is ok.

In the other hand this code works and it is very simple.

import urllib2 as urllib
import json
import pprint

query = {
    "from":0,
    "size":10,
    "query":{
        "field" : { 
            "name" : "david"
        }
    },
    "sort":[
        {"name":"asc"},
        {"lastName":"asc"}
    ]
}

query = json.dumps(query)
response = urllib.urlopen(
    'http://localhost:9200/users/users/_search',
    query
)

result = json.loads( response.read() )

pprint.pprint(result)

So I'm thinking about use the simple code instead of learn the tricks of the libraries.

like image 253
Delta Avatar asked Sep 26 '12 16:09

Delta


1 Answers

There is nothing wrong with your approach of using the REST API to interface with ElasticSearch.

Pyes and the other libraries provide a wrapper around the REST API so that you can write Python code as oppose to building the JSON queries yourself.

like image 194
gjb Avatar answered Sep 30 '22 15:09

gjb