Efficient way to retrieve all _ids in ElasticSearch

后端 未结 11 1795
轮回少年
轮回少年 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 01:53

    Elaborating on the 2 answers by @Robert-Lujo and @Aleck-Landgraf (someone with the permissions can gladly move this to a comment): if you do not want to print but get everything inside a list from the returned generator, here is what I use:

    from elasticsearch import Elasticsearch,helpers
    es = Elasticsearch(hosts=[YOUR_ES_HOST])
    a=helpers.scan(es,query={"query":{"match_all": {}}},scroll='1m',index=INDEX_NAME)#like others so far
    
    IDs=[aa['_id'] for aa in a]
    

提交回复
热议问题