简体   繁体   中英

match all query not returning all documents

I want to read all the documents from my es index. So i using the following function for that:

public List<Map<String, Object>> getAllDocs(){
        System.out.println(indexName+typeName);
        SearchResponse response = client.prepareSearch(indexName)
                .setTypes(typeName)
                .setQuery(QueryBuilders.matchAllQuery())
                .execute()
                .actionGet();

        for(SearchHit hit : response.getHits()){
            //System.out.println("id:"+hit.getId()+" row:"+hit.getSource());
            esData.add(hit.getSource());
        }
        return esData;
    }

But this function only returning 10 documents. If i add one more parameter .setSize(100) then it will return 100 documents. How can i get all the documents in an index without .setSize(100) parameter?

Not really an effective way of doing this, probably because this could be a real performance problem. If you need all records there are at least two ways of doing this:

Using pagination: size and from

Using the scroll api: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html

Another way could be to set a higher size, first do a count query to obtain the count of all items than set the size to this value. But I would never use this solution in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM