【发布时间】:2021-10-26 14:40:09
【问题描述】:
我在弹性搜索中有一个包含大量数据的索引。我正在尝试在 python 中加载它的一些数据(超过 10000 条记录)以进行进一步处理。根据文档和网络搜索,使用了 scroll,但它只能获取少量记录。一段时间后发生此异常,
errorNotFoundError(404, 'search_phase_execution_exception', 'No search context found for id [101781]')
我的代码如下:
from elasticsearch import Elasticsearch
##########elastic configuration
host='localhost'
port=9200
user=''
pasw=''
el_index_name = 'test'
es = Elasticsearch([{'host':host , 'port': port}], http_auth=(user,pasw))
res = es.search(index=el_index_name, body={"query": {"match_all": {}}},scroll='10m')
rows=[]
while True:
try:
rows.append(es.scroll(scroll_id=res['_scroll_id'])['hits']['hits'])
except Exception as esl:
print ('error{}'.format(esl))
break
##deleting scroll
es.clear_scroll(scroll_id=res['_scroll_id'])
我更改了 scroll='10m' 的值,但仍然出现此异常。
【问题讨论】:
标签: python elasticsearch elastic-stack