Python client + Pyes queries

Hello people,

i'm trying to figure out what's the best python client to use. I've started
using pyes, but maybe you have another recommendation.

With pyes, i've a problem, I can't translate this query successfully (it's
just trying to look for "EM" in the user_type):

curl -XGET 'http://127.0.0.1:9200/test_index/user_type/_search?pretty=1' -d
'{

"query" : {
    bool:
       { should: [
           { text: { "first_name": "EM" }},
           { text: { "first_name.partial": "EM" }}
         ]
    }
}

}'

I've done this according the 0.17v docs, but it seems like 0.17 is an unestable branch, and in 0.16 this doesn't work:

q1 = TextQuery("first_name","EM")
q2 = TextQuery("first_name.partial","EM")

q = BoolQuery(should = [q1,q2])

conn.search(q,indices = "test_index",doc_types = "user_type")

Any idea how can I translate the query into a python client?

Thanks!

Hi Santiago,

I've just realized that we're not using pyes for queries, as I
thought. So, even though it's not an answer to your question, below
are the important bits of how we do it using requests and json:

====
import requests, json
#where we run our queries
url='http://localhost:9200/'
#query here as a dictionary
to_search={ "size" : 5, "filter" : { "match_all" : {} } }
#load it
to_search = json.dumps(to_search)
#do the search
result = requests.post(url + '_search', to_search)
#now load the results
results = json.loads(result.content)
#here comes some (quite dirty) error handling
try:
#get the error code, if an error occurred
print "ERROR: HTTP return code is %d." % results["status"]
#get the error message as well
print "Error message was: %s" % results["error"].split("; }{")[0]
return None
except:
#get the number of hits. You can bet there's more interesting
stuff, but this is all we use
hits = results['hits']['total']
#then you have the actual results
actual_results = results['hits']['hits']

Hope this helps. I'm sure you could use this sort of stuff to do
pretty much any kind of query.

Of course this method comes with it's own disadvantages compared to
any kind of ES python client, but I enjoy a straightforward approach.
Especially when I don't do a lot of fancy stuff.

Best regards,
Radu

On Mar 30, 7:25 pm, Santiago Basulto santiago.basu...@gmail.com
wrote:

Hello people,

i'm trying to figure out what's the best python client to use. I've started
using pyes, but maybe you have another recommendation.

With pyes, i've a problem, I can't translate this query successfully (it's
just trying to look for "EM" in the user_type):

curl -XGET 'http://127.0.0.1:9200/test_index/user_type/_search?pretty=1'-d
'{

"query" : {
    bool:
       { should: [
           { text: { "first_name": "EM" }},
           { text: { "first_name.partial": "EM" }}
         ]
    }
}

}'

I've done this according the 0.17v docs, but it seems like 0.17 is an unestable branch, and in 0.16 this doesn't work:

q1 = TextQuery("first_name","EM")
q2 = TextQuery("first_name.partial","EM")

q = BoolQuery(should = [q1,q2])

conn.search(q,indices = "test_index",doc_types = "user_type")

Any idea how can I translate the query into a python client?

Thanks!

Your code should work.
The query object should be passed in a Search object for customizing facet/size/highlighting.

I suggest you to use the latest github version and give a look to pyes/tests/test_query.py for examples.

Hi,
Alberto

Inviato da iPad

Il giorno 30/mar/2012, alle ore 18:25, Santiago Basulto santiago.basulto@gmail.com ha scritto:

Hello people,

i'm trying to figure out what's the best python client to use. I've started using pyes, but maybe you have another recommendation.

With pyes, i've a problem, I can't translate this query successfully (it's just trying to look for "EM" in the user_type):

curl -XGET 'http://127.0.0.1:9200/test_index/user_type/_search?pretty=1' -d '{
"query" : {
bool:
{ should: [
{ text: { "first_name": "EM" }},
{ text: { "first_name.partial": "EM" }}
]
}
}
}'

I've done this according the 0.17v docs, but it seems like 0.17 is an unestable branch, and in 0.16 this doesn't work:

q1 = TextQuery("first_name","EM")
q2 = TextQuery("first_name.partial","EM")

q = BoolQuery(should = [q1,q2])

conn.search(q,indices = "test_index",doc_types = "user_type")

Any idea how can I translate the query into a python client?

Thanks!