Pagination in elasticsearch

I have

SearchRequestBuilder srb = client.prepareSearch("cs").setTypes("csdl");
srb.setSearchType(SearchType.DFS_QUERY_AND_FETCH);

QueryBuilder qb = (QueryBuilder) QueryBuilders.matchQuery("title",
searchText);

FilterBuilder fb = FilterBuilders.andFilter (
FilterBuilders.termsFilter("elasticdb", searchDB),
//get from date and to date

FilterBuilders.rangeFilter("pubdate").gte("1890-09").lte("2014-08")
);

FilteredQueryBuilder builder = QueryBuilders.filteredQuery(qb,fb);

FunctionScoreQueryBuilder functionbuilder = new
FunctionScoreQueryBuilder(builder)
.add(FilterBuilders.termsFilter("category",
"acm"), factorFunction(-30.0f));

srb.setQuery(functionbuilder).setFrom(0).setSize(1);

SearchResponse response = srb.execute().actionGet();
SearchHit[] results = response.getHits().getHits();

Even though I set from=0 and size = 1 ( to see only one result) I see more
than 1 results.

How do we get this pagination working?

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/847b621d-4638-4096-8159-54ca97cf03d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The setSize method specifies the maximum number of responses per shard.

So if you query an index with N shards and your query sets a size of S then
the query will return a maximum of up to N x S response hits.

Since you writing this in Java, it's a relatively easy matter to make
further adjustments on the response, limiting the response to the page size
you expect.

Brian

On Thursday, September 25, 2014 6:56:44 PM UTC-4, Malini wrote:

I have

SearchRequestBuilder srb = client.prepareSearch("cs").setTypes("csdl");
srb.setSearchType(SearchType.DFS_QUERY_AND_FETCH);

QueryBuilder qb = (QueryBuilder) QueryBuilders.matchQuery("title",
searchText);

FilterBuilder fb = FilterBuilders.andFilter (
FilterBuilders.termsFilter("elasticdb", searchDB),
//get from date and to date

FilterBuilders.rangeFilter("pubdate").gte("1890-09").lte("2014-08")
);

FilteredQueryBuilder builder = QueryBuilders.filteredQuery(qb,fb);

FunctionScoreQueryBuilder functionbuilder = new
FunctionScoreQueryBuilder(builder)

.add(FilterBuilders.termsFilter("category", "acm"), factorFunction(-30.0f));

srb.setQuery(functionbuilder).setFrom(0).setSize(1);

SearchResponse response = srb.execute().actionGet();
SearchHit results = response.getHits().getHits();

Even though I set from=0 and size = 1 ( to see only one result) I see more
than 1 results.

How do we get this pagination working?

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/00c324bd-fad1-404c-8b28-4274ffe11c24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.