Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 614
Dinoop Nair Avatar asked Mar 22 '14 12:03

Dinoop Nair


1 Answers

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.

like image 115
Jettro Coenradie Avatar answered Oct 14 '22 04:10

Jettro Coenradie