Builder setSize(X) returns a lot more than X?


(TimOnGmail) #1

Hi all...

So I'm trying to use Elastic Search, but am having some difficulties.

The latest one is, in code like this:


  SearchRequestBuilder builder = client.prepareSearch(index);
  builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
  builder = builder.setQuery(new

QueryStringQueryBuilder(queryString));
builder = builder.setFrom(startIndex);
builder = builder.setSize(maxResults);
builder = builder.setExplain(true);
ListenableActionFuture future =
builder.execute();
response = future.actionGet(MAX_WAIT_MILLIS);
SearchHits hits = response.getHits();


hits.getTotalHits() is some reasonable number

However, hits.getHits().length is always BIGGER than maxResults.

From the documentation, it looks like I"m supposed to just get, at
most, maxResults hits back, but I'm always getting more than that
back.

Does anyone know why that might be happening? Am I doing something
wrong here?

  • Tim

(Hari Shankar) #2

Hi,

Query and fetch would return size*number of shards results. (
http://www.elasticsearch.org/guide/reference/api/search/search-type.html).

hari

On Mon, Jul 11, 2011 at 1:18 PM, TimOnGmail timbessie@gmail.com wrote:

Hi all...

So I'm trying to use Elastic Search, but am having some difficulties.

The latest one is, in code like this:


 SearchRequestBuilder builder = client.prepareSearch(index);
 builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
 builder = builder.setQuery(new

QueryStringQueryBuilder(queryString));
builder = builder.setFrom(startIndex);
builder = builder.setSize(maxResults);
builder = builder.setExplain(true);
ListenableActionFuture future =
builder.execute();
response = future.actionGet(MAX_WAIT_MILLIS);
SearchHits hits = response.getHits();


hits.getTotalHits() is some reasonable number

However, hits.getHits().length is always BIGGER than maxResults.

From the documentation, it looks like I"m supposed to just get, at
most, maxResults hits back, but I'm always getting more than that
back.

Does anyone know why that might be happening? Am I doing something
wrong here?

  • Tim

(TimOnGmail) #3

Ahhh, thanks Hari!

  • Tim

On Jul 11, 1:36 am, Hari Shankar shaan.h...@gmail.com wrote:

Hi,

Query and fetch would return size*number of shards results. (http://www.elasticsearch.org/guide/reference/api/search/search-type.html).

hari

On Mon, Jul 11, 2011 at 1:18 PM, TimOnGmail timbes...@gmail.com wrote:

Hi all...

So I'm trying to use Elastic Search, but am having some difficulties.

The latest one is, in code like this:


 SearchRequestBuilder builder = client.prepareSearch(index);
 builder = builder.setSearchType(SearchType.DFS_QUERY_AND_FETCH);
 builder = builder.setQuery(new

QueryStringQueryBuilder(queryString));
builder = builder.setFrom(startIndex);
builder = builder.setSize(maxResults);
builder = builder.setExplain(true);
ListenableActionFuture future =
builder.execute();
response = future.actionGet(MAX_WAIT_MILLIS);
SearchHits hits = response.getHits();


hits.getTotalHits() is some reasonable number

However, hits.getHits().length is always BIGGER than maxResults.

From the documentation, it looks like I"m supposed to just get, at
most, maxResults hits back, but I'm always getting more than that
back.

Does anyone know why that might be happening? Am I doing something
wrong here?

  • Tim

(system) #4