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.