elasticsearch type_error ai_generated true

查询分片异常:创建查询失败:提升值必须为正数,得到[-2.0]

QueryShardException: failed to create query: boost must be positive, got [-2.0]

ID: elasticsearch/invalid-boost-in-query

其他格式: JSON · Markdown 中文 · English
92%修复率
88%置信度
1证据数
2023-11-20首次发现

版本兼容性

版本状态引入弃用备注
7.17.0 active
8.10.0 active
8.13.0 active

根因分析

查询DSL中的负值或零提升值(例如在function_score查询或term查询中)违反了提升值必须为正浮点的要求。

English

A negative or zero boost value in a query DSL, such as in a function_score query or term query, violates the requirement that boost must be a positive float.

generic

官方文档

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

解决方案

  1. 将提升值改为正浮点数,例如在function_score查询中:{ "function_score": { "query": { "match": { "field": "value" } }, "boost": 0.5 } }
  2. 使用script_score查询并确保提升值正数:{ "script_score": { "query": { "match_all": {} }, "script": { "source": "Math.max(_score, 0.01)" } } }

无效尝试

常见但无效的做法:

  1. 70% 失败

    Index-time boost is deprecated and ignored; the error is about query-time boost, not mapping boost

  2. 85% 失败

    Negative boost is not supported; use a 'must_not' clause or script_score with negation instead