如何从弹性搜索索引检索所有文档ID [英] How to retrieve all the document ids from an elasticsearch index

查看:107
本文介绍了如何从弹性搜索索引检索所有文档ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从弹性搜索索引中检索所有文档ID(内部文档_id)?如果我在该索引中有2000万个文档,那么最好的方法是什么?

How to retrieve all the document ids (the internal document '_id') from an Elasticsearch index? if I have 20 million documents in that index, what is the best way to do that?

推荐答案

您可能希望使用扫描和滚动API

许多客户端库都有准备好的帮助程序来使用该界面。例如,使用elasticsearch-py,您可以执行以下操作:

Many client libraries have ready helpers to use the interface. For example, with elasticsearch-py you can do:

es = elasticsearch.Elasticsearch(eshost)
scroll = elasticsearch.helpers.scan(es, query='{"fields": "_id"}', index=idxname, scroll='10s')
for res in scroll:
        print res['_id']

这篇关于如何从弹性搜索索引检索所有文档ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆