gpt4 book ai didi

elasticsearch - 设置 index.max_terms_count 没有效果?

转载 作者:行者123 更新时间:2023-12-05 06:28:11 31 4
gpt4 key购买 nike

我正在试验 index.max_terms_count。我尝试执行一个包含超过 65 536 个术语的术语查询,我很惊讶地看到它实际上被执行了,因为我读到了警告 here :

Executing a Terms Query request with a lot of terms can be quite slow, as each additional term demands extra processing and memory. To safeguard against this, the maximum number of terms that can be used in a Terms Query both directly or through lookup has been limited to 65536 . This default maximum can be changed for a particular index with the index setting index.max_terms_count .

为了进一步测试它,我尝试将 index.max_terms_count 设置为 2 或 3,但它仍然无法按我预期的方式工作。你能帮我理解我在做什么(或理解)错了吗?

步骤:

  1. 使用 Docker 运行 ES:

    1.1.docker pull docker.elastic.co/elasticsearch/elasticsearch:6.6.0

    1.2。 docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"docker.elastic.co/elasticsearch/elasticsearch:6.6.0

  2. 索引文档:curl -X POST http://localhost:9200/twitter/_doc/1 -H '内容类型:应用程序/json' -d '{ “用户”:“泡菜”, “发布日期”:“2009-11-15T14:12:12”, "message": "试用 Elasticsearch", “标签”:[“富”,“酒吧”,“太阳”,“云”]}'

  3. 更改设置:curl -X PUT http://localhost:9200/twitter/_settings -H '内容类型:应用程序/json' -d '{ “指数” : { “max_terms_count”:2 }}'

  4. 验证设置是否已应用:curl -X GET http://localhost:9200/twitter/_settings

  5. 执行搜索:curl -X POST ' http://localhost:9200/twitter/_search?pretty ' -H '内容类型:application/json' -d '{ “询问”: { “条款”:{“标签”:[“太阳”,“多云”,“哟”,“嗨”,“你好”]} }}'

最佳答案

在 ElasticSearch 版本 7.0 之后,index.max_terms_count 的默认值为 65536,如果您使用默认 向 terms 命令提供超过 65536 的额外输入max_terms_count 设置。例如,65537,它将产生以下异常消息

{
"error" : {
"root_cause" : [
{
"type" : "query_shard_exception",
"reason" : "failed to create query: The number of terms [65537] used in the Terms Query request has exceeded the allowed maximum of [65536]. This maximum can be set by changing the [index.max_terms_count] index level setting.",
"index" : "my_index",
"index_uuid" : "iJMNOR7znSsmODsG4uArTvQ"
},
....
....
...
}

Elastic search 提供了一种将 max_terms_count 增加到 2147483647 的方法。出于测试目的,我尝试设置到 2147483647,并且效果很好

PUT /my-index/_settings
{
"index" : {
"max_terms_count" : 2147483647
}
}

但是当我开始将值增加到 2147483648

时失败了
PUT /my-index/_settings
{
"index" : {
"max_terms_count" : 2147483648
}
}



{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Failed to parse value [2147483648] for setting [index.max_terms_count]"
}
],
"type" : "illegal_argument_exception",
"reason" : "Failed to parse value [2147483648] for setting [index.max_terms_count]",
"caused_by" : {
"type" : "number_format_exception",
"reason" : "For input string: \"2147483648\""
}
},
"status" : 400
}

因此,max_terms_count 确实在查询期间发挥作用,并且您的 index.max_terms_count 根据您的配置(有或没有默认)产生影响

关于elasticsearch - 设置 index.max_terms_count 没有效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54520671/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com