Elasticsearch:尽管total大于0,但是空命中数组

时间:2016-01-14 13:38:31

标签: node.js elasticsearch

对于以下查询

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

我收到了以下答案

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

        ]
      }
    }

我在同一主题上发现了这篇文章https://discuss.elastic.co/t/hits-hits-array-empty-even-thought-total-1/19930但仍然不明白,如何解决我的问题,因为我认为

from: 1
将根据他的解决方案解决问题。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

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.

我遇到了同样的问题,我可以看到total_hits为1,返回空数组。我发现我将默认的pageNum设置为1,但是弹性搜索从0开始,因此在使用pageNum查询为1时返回第二页