Efficient way to retrieve all _ids in ElasticSearch

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

    This is working!

    def select_ids(self, **kwargs):
        """
    
        :param kwargs:params from modules
        :return: array of incidents
        """
        index = kwargs.get('index')
        if not index:
            return None
    
        # print("Params", kwargs)
        query = self._build_query(**kwargs)
        # print("Query", query)
    
        # get results
        results = self._db_client.search(body=query, index=index, stored_fields=[], filter_path="hits.hits._id")
        print(results)
        ids = [_['_id'] for _ in results['hits']['hits']]
        return ids
    

提交回复
热议问题