Using "fields" in pyes requests, with error 0.19.1

Trying to use fields = [...] paramater in pyes.search not working

Here is a simple test script to illustrate the problem: http://pastebin.com/LiRMC3ib

Using the current release of pyes 0.19.1, this script outputs {} as a result

print resultset[0] 

However, using the previous "old" unstable version of pyes 0.19.1, which I have is 0.19.1 (unstable), the result

 print resultset[0] 

is expected:

 {u'name': u'Joe Tester'} 

Using fields in an ES.get call really works.

Has anyone else seen this or had some guidance as to what?

+4
source share
5 answers

rewrite

 resultset = ES.search(query=q, indices='oolong', fields=["name"]) 

to

 resultset = ES.search(Search(q, fields=['name']), indices='oolong')) 
+2
source

One thing that I notice in your pastebin code that may explain unexpected behavior is the update (line 37) should be before the search (line 36). Otherwise, there is a race condition if the document is not already listed in the index.

+1
source

I am using pyes 0.19.1 with the same problem, but I can get one field from the result set.

Replace this line:

 resultset = ES.search(query=q, indices='oolong', fields=["name"]) 

to that:

 resultset = ES.search(query=q, indices='oolong', fields="name") 

This works for me. However, I did not understand how to get multiple fields. When I pass the list to the fields, it always returns empty dictionaries.

+1
source

Take a look:

 class pyes.query.Search(...) 

There you can set an array of fields. Fields in ES.search do not work.

 es_connection = ES(server=[('http', 'localhost', '9200')]) q = Search(fields=['field1', 'field2'], .....) resultset = es_connection.search( q, .... ) 
0
source

Use this

 resultset = ES.search(query=q, indices='oolong', fields="name") 

or if more than one field is used

 resultset = ES.search(query=q, indices='oolong', fields="name,id") 
0
source

Source: https://habr.com/ru/post/1447953/


All Articles