ElasticSearch查询超时时如何终止?

f45qwnt8  于 2023-02-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(288)

这是我的查询HTTP POST

网址http://127.0.0.1:9200/-2023.02./_search?timeout=10ms
请求

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "event.code": "1"
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "@timestamp": {
                "order": "asc"
            }
        }
    ],
    "size": 10000
}

答复

{
    "took": 1557,
    "timed_out": false,
    "_shards": {
        "total": 984,
        "successful": 984,
        "skipped": 826,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

我可以问一下为什么我把超时设置为10ms,但花费的时间是1557ms(take)吗?
如何设置超时以便Elastic终止查询?
ElasticSearch版本7.8.1。

6g8kf2rb

6g8kf2rb1#

timeout参数是per shard。如果在一个shard上花费的时间超过了超时值,则取消对该shard的当前搜索,并返回在此之前收集的命中。
正如您所看到的,您有984个碎片,因此如果您有一个节点和一个处理器,那么理论上需要9.84秒才能返回10毫秒的超时。这可能不是您的情况,因为查询在1.5秒内返回,但这只是为了说明超时没有按照您期望的方式工作。

相关问题