Efficient way to retrieve all _ids in ElasticSearch

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

    For Python users: the Python Elasticsearch client provides a convenient abstraction for the scroll API:

    from elasticsearch import Elasticsearch, helpers
    client = Elasticsearch()
    
    query = {
        "query": {
            "match_all": {}
        }
    }
    
    scan = helpers.scan(client, index=index, query=query, scroll='1m', size=100)
    
    for doc in scan:
        # do something
    

提交回复
热议问题