Elasticsearch 查询通过搜索后命中丢失的文档

Elasticsearch query hits missing documents by search after

查询elasticsearch 6.8的时候有点问题。我在文档中有一个 createdAt 信息,我正在使用 createdAt 信息进行搜索

我的查询是:

{
  "from": 0,
  "size": 2500,
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {
                        "field": "uni",
                        "boost": 1
                      }
                    }
                  ],
                  "adjust_pure_negative": true,
                  "boost": 1
                }
              },
              {
                "match": {
                  "uni": {
                    "query": "false",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "auto_generate_synonyms_phrase_query": true,
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "minimum_should_match": "1",
            "boost": 1
          }
        },
        {
          "exists": {
            "field": "pt",
            "boost": 1
          }
        }
      ],
      "should": [
        {
          "bool": {
            "must_not": [
              {
                "exists": {
                  "field": "del",
                  "boost": 1
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "match": {
            "del": {
              "query": false,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "minimum_should_match": "1",
      "boost": 1
    }
  },
  "_source": {
    "includes": [
      "did",
      "ca"
    ],
    "excludes": []
  },
  "sort": [
    {
      "ca": {
        "order": "asc"
      }
    }
  ],
  "search_after": [
    1596545647769
  ]
}

我有一个 100k 文档,但通过这种方式我命中了 99.996 个文档,问题是 totalHits 显示了 100.000,但是当我在 kibana 上查询时,它给我最后一批 4 个丢失的文档。例如,我将我的文档作为 2500 个文档批次获取,在最后一个批次中,它应该是从 97.500 到 100.000,但它给了我 99.996。

当我使用搜索滚动 api 对 2500 个文档批次执行相同的查询时,它给了我 100.000 个文档。

注意:如果我使用搜索滚动,我使用滚动键才能继续。如果我之后使用搜索,我将使用 createdAt 信息来获取下一个文档。 什么会导致此问题?

如果有任何文档可能包含 ca 字段的完全相同的值,那么解决方案是简单地在 sort 子句中使用另一个决胜字段,以便两个文档ca相同的值仍然可以正确排序。

像这样:

  "sort": [
    {
      "ca": {
        "order": "asc"
      }
    },
    {
      "tie_breaker_field": {
        "order": "asc"
      }
    }
  ],