ES return more hits than I expected

ES version: 2.4.2

I use transport client to sent a search request to an ES index which has 5 shards, request parameter: from=0, size=10. And then, I got 50 hits back (10 hits per shard, I think). But if I changed from parameter to something greater than 0, then I got only 10 hits back (that's what I expect).

I didn't find any explanation on this behavior.

So, any documents here?

This sounds like Pagination. Be it 10 results from the 5 shards. Can you share more on the exact search you are running and what you wanting to achieve.

@JKhondhu
I pasted my request below, and I use java transport client to send request

{
  "from" : 0,
  "size" : 10,
  "query" : {
    "bool" : {
      "must" : {
        "query_string" : {
          "query" : "abcd",
          "fields" : [ "description^1.0", "content^3.0", "title^6.0", "url_token^3.0" ],
          "analyzer" : "keyword",
          "boost" : 2.0
        }
      }
    }
  }
}

What I want to achieve is that if I search with from=0 and size=10, then I should get only 10 hits, not 50 hits. And I'm sure it's something about shard. I tried to change index shard num to 3, then I got 30 hits.

@ji_luo What are you hoping to achieve here? You mention the transport client. Is this a one time query to get the top ten? (example) Top ten movies with the fields you have provided?

What will your application be doing with the queried data?

@JKhondhu

I solved the problem.

In case other people may encounter the same problem, I will write down the reason here.

The problem is caused by different search types, if I use default search type query_then_fetch, the returned hit count is as I expected, but if I use query_and_fetch, it will return num_of_shards * size hits, more than I want, it adds more burden on network, and increases response time.

Good to hear @ji_luo

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.