저는 Python을 사용하여 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에서 딕셔너리를 얻을 수있었습니다 : 이전 링크를 기반으로, 나는이 시도했습니다? 결과 집합을 사전의 (목록)으로 효율적으로 변환하는 데 좋은 해결 방법도 있습니다.
당신은 DICT 또는 유사한로 변환하려고해서는 안 : 여기
내가 사용하는 방법입니다. 동일한 작업이 두 번 수행됩니다. 내가 한 일은 DottedDict 액세스를 사용하지 않는 ES 개체를 덮어 쓴 것입니다. 그러나 또 다른 가능성은 사용자에게 원시 쿼리입니다. –