我使用Elasticsearch Python API根据存储在ES群集中的数据计算某些内容。对于我的计算,我需要调用所有满足一定条件的文档,并从中获得某些信息。因此我正在做一个大小为1000并且持续时间为1秒的滚动。我写了一个Python脚本,它使用ES-Python为我完成这项工作。使用Python API在Elasticsearch中滚动时发生分段错误
但是,总是在超过1400个卷轴之后脚本退出并显示错误“Segmentation fault (core dumped)
”。我试图将滚动大小增加到10000,但仍然发生相同的问题。以下是脚本的,我正在做的滚动部分:
page = Elasticsearch().search(index = my_index, scroll = "1s", size = 1000, body = { "_source" : [ "_id", "@timestamp", my_field], "query" : {"bool":{"must" : [{"exists":{ "field" : my_field }},{"exists":{ "field" : "@timestamp" }}]}}})
sid = page['_scroll_id']
scroll_size = page['hits']['total']
while (scroll_size > 0):
print "Scrolling..."
# Get the number of results that we returned in the last scroll
scroll_size = len(page['hits']['hits'])
print "scroll size: " + str(scroll_size)
page = Elasticsearch().scroll(scroll_id = sid, scroll = '1s')
# Update the scroll ID
sid = page['_scroll_id']
我可以找出该行page = Elasticsearch().scroll(scroll_id = sid, scroll = '1s')
负责错误。我已经检查过滚动ID,它总是一样的(至少在错误被抛出之前)。 有人遇到过类似的问题,或者有人知道如何解决这个问题吗?
我在OS Ubuntu 14.04的同一台服务器上同时运行Python和Elasticsearch。 Python版本是2.7.6和ES版本是5.0.0
你有没有考虑过使用扫描助手呢? (http://elasticsearch-py.readthedocs.io/en/master/helpers.html#elasticsearch.helpers.scan) – iCart
我以前不知道。有使用扫描助手的任何工作示例?我一直在尝试,但无法弄清楚它是如何工作的。 – mshabeeb