Efficient way to retrieve all _ids in ElasticSearch

后端 未结 11 1797
轮回少年
轮回少年 2021-01-31 01:31

What is the fastest way to get all _ids of a certain index from ElasticSearch? Is it possible by using a simple query? One of my index has around 20,000 documents.

11条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 02:11

    Inspired by @Aleck-Landgraf answer, for me it worked by using directly scan function in standard elasticsearch python API:

    from elasticsearch import Elasticsearch
    from elasticsearch.helpers import scan
    es = Elasticsearch()
    for dobj in scan(es, 
                     query={"query": {"match_all": {}}, "fields" : []},  
                     index="your-index-name", doc_type="your-doc-type"): 
            print dobj["_id"],
    

提交回复
热议问题