我使用PyES在Python中使用ElasticSearch。 通常情况下,我建我的查询的格式如下:如何在PyES中使用ResultSet
# Create connection to server.
conn = ES('127.0.0.1:9200')
# Create a filter to select documents with 'stuff' in the title.
myFilter = TermFilter("title", "stuff")
# Create query.
q = FilteredQuery(MatchAllQuery(), myFilter).search()
# Execute the query.
results = conn.search(query=q, indices=['my-index'])
print type(results)
# > <class 'pyes.es.ResultSet'>
这完美的作品。当查询返回大量文档时,我的问题就开始了。 将结果转换为词典列表的计算要求很高,所以我试图返回字典中的查询结果。我碰到这个文档:
http://pyes.readthedocs.org/en/latest/faq.html#id3 http://pyes.readthedocs.org/en/latest/references/pyes.es.html#pyes.es.ResultSet https://github.com/aparo/pyes/blob/master/pyes/es.py(线1304)
但我无法弄清楚到底我应该做的事情。 根据前面的链接,我已经试过这样:
from pyes import *
from pyes.query import *
from pyes.es import ResultSet
from pyes.connection import connect
# Create connection to server.
c = connect(servers=['127.0.0.1:9200'])
# Create a filter to select documents with 'stuff' in the title.
myFilter = TermFilter("title", "stuff")
# Create query/Search object.
q = FilteredQuery(MatchAllQuery(), myFilter).search()
# (How to) create the model ?
mymodel = lambda x, y: y
# Execute the query.
# class pyes.es.ResultSet(connection, search, indices=None, doc_types=None,
# query_params=None, auto_fix_keys=False, auto_clean_highlight=False, model=None)
resSet = ResultSet(connection=c, search=q, indices=['my-index'], model=mymodel)
# > resSet = ResultSet(connection=c, search=q, indices=['my-index'], model=mymodel)
# > TypeError: __init__() got an unexpected keyword argument 'search'
任何人都能够得到从结果的字典? 有效地将ResultSet转换为(列表)字典的好消息也将被赞赏。
你不应该试图把它转换成一个字典或类似的。 这将做两次相同的事情。我所做的是覆盖ES对象,它不使用DottedDict访问。但另一种可能性是使用“原始查询”。 – 2014-01-21 23:52:43