How to make pyes search method to return the keys of the found documents?

I have a question about pyes (Python API of the ElasticSearch).

Is it possible to make the search method to return the keys of the found documents?

The code I use:

import pyes
conn = pyes.ES('localhost:9200')
q = pyes.StringQuery("november rain", default_operator="AND")
result = conn.search(query=q, indices=[index])
for r in result:
    print r

Result: found documents, without the key (_id field) that I saved the document with.

The question is how to return the _id keys?

Thanks!

Answers


All results in a ResultSet are just ElasticSearchModel objects. So you can access the _id attribute via the _meta DotDict like this

r._meta.id

_meta also contains some other useful information:

(Pdb) pp res._meta
{'connection': <pyes.es.ES object at 0x8268ecc>,
 u'id': u'2',
 u'index': u'twitter',
 'parent': None,
 u'score': 0.095891505000000002,
 u'type': u'tweet'}

See the documentation on models and result sets for more details.


Need Your Help

Three js - Cloning a shader and changing uniform values

clone shader textures webgl three.js

I'm working on creating a shader to generate terrain with shadows.

Why can properties not be public inside a ref class sealed

c++ pointers direct3d c++-cx

The following code is illegal ( Visual Studio 2012 Windows Phone( Creating a windows phone direct3d app ) )

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.