ES7.5.2 script_score查询的bug

背景

1.需要用到dense_vector + script_score来进行算分 --- 排序

2.ES版本为7.5.2,用到了自定义的插件,短期无法升级到7.17.5(或更高版本)

3.script_score查询在加入date类型的字段作为查询条件时,出现NPE异常

case

1. 索引mapping

PUT zmc-test
{
    "aliases": {},
    "mappings": {
      "dynamic": "false",
      "properties": {
        "dataChange_LastTime": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        },
        "features": {
          "type": "dense_vector",
          "dims": 128
        }
      }
    }
}

2. 查询语句

GET zmc-test/_search
{
	"size": 50,
	"query": {
		"script_score": {
			"query": {
				"bool": {
					"must": [{
						"range": {
							"dataChange_LastTime": {
								"from": "2022-01-02 22:57:02",
								"to": "2022-12-31 18:05:20",
								"include_lower": true,
								"include_upper": true,
								"boost": 1.0
							}
						}
					}]
				}
			},
			"script": {
				"source": "cosineSimilarity(params.queryVector, doc['features'])+1.0",
				"lang": "painless",
				"params": {
					"queryVector": [-3.3732865, -0.088037536, 0.000...., -0.17549877]
				}
			},
			"boost": 1.0
		}
	},
	"_source": {
		"includes": ["xxx", "xxx"],
		"excludes": []
	}
}

3.异常信息

{
  "error": {
    "root_cause": [
      {
        "type": "null_pointer_exception",
        "reason": null
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "zmc-test",
        "node": "tc3gB-p-TNOIbLJkaNk8uw",
        "reason": {
          "type": "null_pointer_exception",
          "reason": null
        }
      }
    ],
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null,
      "caused_by": {
        "type": "null_pointer_exception",
        "reason": null
      }
    }
  },
  "status": 500
}

4. 猜测是date类型format的问题,换成默认date类型依然报错

`strict_date_optional_time||epoch_millis`


如:
{
  "date": "2022-01-01T12:00:00.000+0800",
  "timestamp": 1641004800000
}

5.测试其他类型(非date,如long、int等类型range查询均正常),测试其他ES版本,7.17.5版本date类型也正常

原因分析 TODO

解决方案

1. 换成long类型,数据存timestamp

2. 升级版本到7.17.5或或更高

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值