Efficient way to retrieve all _ids in ElasticSearch

后端 未结 11 1809
轮回少年
轮回少年 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:47

    you can also do it in python, which gives you a proper list:

    import elasticsearch
    es = elasticsearch.Elasticsearch()
    
    res = es.search(
        index=your_index, 
        body={"query": {"match_all": {}}, "size": 30000, "fields": ["_id"]})
    
    ids = [d['_id'] for d in res['hits']['hits']]
    

提交回复
热议问题