简体   繁体   中英

Elasticsearch: empty hits array although total is greater than 0

For the following query

    {
        index: i,
        from: 0,
        size: 10,
        body: {
            query: {
                filtered: {
                    query: {
                        term: { "si" : si}
                    }
                }                       
            }
        }               
    }

I get returned the following answer

    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
      },
      "hits": {
        "total": 4,
        "max_score": 5.1108737,
        "hits": [

        ]
      }
    }

I found this post on the same topic https://discuss.elastic.co/t/hits-hits-array-empty-even-thought-total-1/19930 but still don't understand, how to solve my problem, since I thought

from: 1

would according to his solution solve the issue.

Thanks for your help

By default, elasticsearch starts showing its  Query results from pageNum as 0 and the search query we define generally start from pageNum as 1.
Ensure that if you are setting the pageNum, it is set to 0 in case you have the resultset within the pageSize limit.

I was facing the same issue where I could see total_hits as 1 with empty array being returned. I found that I was setting the default pageNum to 1 ,however elasticsearch starts it from 0 and hence was returning the second page when queried with pageNum as 1

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