首页 > 解决方案 > Elasticsearch - 只要我使用正确的开始时间,在我的初始查询中使用“searchafter”有什么问题吗?

问题描述

根据文档,对弹性进行初始查询,从中检索排序时间戳。然后我使用 'searchafter' 进行后续查询,每次更改排序时间戳以检索我需要的记录。

例如:

   `{"query":{"bool":{"must":[{"bool":{"must":[{"bool":{"must":[{"range":{"Timestamp":{"gte":${stUnix},"format": "epoch_millis"}}},{"range":{"Timestamp":{"lte":${endUnix},"format": "epoch_millis"}}}]}}]}}]}},"sort":{"Timestamp": {"order":"asc"}},"size":${dateRadio}, "script_fields" : {
      "test1" : {
          "script" : {
              "lang": "painless",
              "source": "doc['InitiatorBytes'].value + doc['ResponderBytes'].value"
          }
      }
  },"_source":{"includes":["*"],"excludes":[]},"from":0}\n`;

运行此初始查询后,我使用响应中的排序时间戳来运行后续查询。

`{"query":{"bool":{"must":[{"bool":{"must":[{"bool":{"must":[{"range":{"Timestamp":{"gte":${stUnix},"format": "epoch_millis"}}},{"range":{"Timestamp":{"lte":${endUnix},"format": "epoch_millis"}}}]}}]}}]}},"search_after":[${sortUnix}],"sort":{"Timestamp": {"order":"asc"}},"size":${dateRadio},"_source":{"includes":["*"],"excludes":[]},"from":0}\n`

在上面,我将 sortunix 变量设置为我从初始查询中检索到的排序时间戳。对于所有后续查询,我只使用上面的内容并插入排序时间戳响应。在这两个查询中,我在 gte:'stUnix' 中设置了相同的初始开始时间

我的问题是是否可以取消第一个查询并将初始 searchafter 'sortunix' 变量设置为等于 'stunix' 变量。

我试过这样做,它似乎工作正常,但我不确定它是否会影响数据的完整性。

标签: elasticsearchsearchterm

解决方案


推荐阅读