elasticsearch报错: illegal argument exception, variable is not found
最近在给es升级,从es2.3.3升级到es6.0.0, 由于新版的es不支持ScriptType.FILE类型,所以打算改成STORE类型。于是按照官方文档添加script:
curl -XPOST -H 'Content-Type:application/json' 'http://localhost:9200/_scripts/video_hot_score' -d '{"script": {"lang" : "painless", "source" : "doc['hot_score'].value/((2+(params.current-doc['publish_time'].value)/86400000.0)*1.7)+1"}
}'
然后在代码里面使用这个script:
Map<String, Object> params = new HashMap<String, Object>();params.put("current", System.currentTimeMillis());Script script = new Script(ScriptType.STORED, null, "video_hot_score", params);ScoreFunctionBuilder scorefuntion = ScoreFunctionBuilders.scriptFunction(script);
直接报错:
Caused by: ScriptException[compile error]; nested: IllegalArgumentException[Variable [hot_score] is not defined.];at org.elasticsearch.painless.PainlessScriptEngine.convertToScriptException(PainlessScriptEngine.java:536)at org.elasticsearch.painless.PainlessScriptEngine.compile(PainlessScriptEngine.java:439)at org.elasticsearch.painless.PainlessScriptEngine.compile(PainlessScriptEngine.java:131)at org.elasticsearch.script.ScriptService.compile(ScriptService.java:335)at org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder.doToFunction(ScriptScoreFunctionBuilder.java:95)at org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder.toFunction(ScoreFunctionBuilder.java:138)at org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.doToQuery(FunctionScoreQueryBuilder.java:298)at org.elasticsearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:98)at org.elasticsearch.index.query.QueryShardContext.lambda$toQuery$2(QueryShardContext.java:311)at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:323)at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:310)at org.elasticsearch.search.SearchService.parseSource(SearchService.java:669)
首先确认该索引的mapping里面是有hot_score这个字段的,谷歌了好久,发现问题出在对引号的编码上。把添加的script里面单引号写成unicode编码的形式即可,如下:
curl -XPOST -H 'Content-Type:application/json' 'http://localhost:9200/_scripts/video_hot_score' -d '{"script": {"lang" : "painless", "source" : "doc[\u0027hot_score\u0027].value/((2+(params.current-doc[\u0027publish_time\u0027].value)/86400000.0)*1.7)+1"}
}'
elasticsearch报错: illegal argument exception, variable is not found相关推荐
- [mongoDB]使用Studio 3T连接MongoDB报错Illegal argument: For input string: “23-28-g865b4f6a96“
使用Studio 3T做MongoDB客户端连接报错,但是使用robo3t正常连接 如图,MongoDB正常启动: 但Studio 3T连接报错: 通过报错我们可以明白,这是由于MongoDB的版本中 ...
- Junit报错:Argument(s) are different! Wanted:
本人个人博客网站,欢迎访问:学教府 在controller中的方法如下: /*** 处理注册的提交信息* @param spitter* @return*/@RequestMapping(value ...
- windows运行elasticsearch报错Native memory allocation (mmap) failed to map 4294967296 bytes for G1
今天下载了一个elasticsearch8.4.3 windows版本的es,配置好相应的配置后,启动bat文件,输出一行信息后,窗口就闪退了.于是通过cmd窗口运行,发现了报错信息如下 Except ...
- elasticsearch报错expected <block end>, but found BlockMappingStart解决方法
elasticsearch报错expected , but found BlockMappingStart解决方法 参考文章: (1)elasticsearch报错expected , but fou ...
- 解决MySQL8.0报错:Unknown system variable 'validate_password_policy'
解决MySQL8.0报错:Unknown system variable 'validate_password_policy' 一.问题描述 1.在安装MySQL8.0时,修改临时密码,因密码过于 ...
- 错误:java.lang.Illegal Argument Exception: Document base F:/apache-tomcat-7.0.40/webapps/ web3 does no
MyEclipse部署Tomcat时,出现以下问题: 错误:java.lang.Illegal Argument Exception: Document base F:/apache-tomcat-7 ...
- hive日志位置(日志定位报错:Failed with exception Unable to move sourcehdfs://namenode/tmp/hive-pmp_bi/h)...
Hive中的日志分为两种 1. 系统日志,记录了hive的运行情况,错误状况. 2. Job 日志,记录了Hive 中job的执行的历史过程. 日志查看方法 1,在本地运行机器上 hive日志存储位置 ...
- jetson nano 报错Illegal instruction(core dumped)
jetson nano 报错Illegal instruction(core dumped) 问题描述:好不容易对jetson nano开发板更换好镜像源.配置好远程xrdp桌面(可以参考我往期博文) ...
- ElasticSearch报错:FORBIDDEN/12/index read-only / allow delete (api)无法写入
背景 一个两年前的读书笔记项目,在本地开发环境启动后,搜索服务的后端日志 ElasticSearch 报错:FORBIDDEN/12/index read-only / allow delete (a ...
最新文章
- 擒贼先擒王,简单谈一下JavaScript作用域链(Scope Chain)
- nginx: [error] invalid PID number in /usr/local/webserver/nginx/logs/nginx.pid
- SAP Spartacus table里显示较长数据时自动显示省略号的设置
- django之快速分页
- 《无线网络:理解和应对互联网环境下网络互连所带来的挑战》——第2章 无线生态系统 2.1无线标准化过程...
- SSM项目使用example查询时多次查询条件相同
- SSO (单点登录)实现方式
- 什么是koa中间件,他们的执行顺序是什么样的?
- 春节健康膳食,合理配搭
- 4.1Python文件基本操作
- android 弹幕礼物,Android B站开源的弹幕库的用法以及坑
- python物业管理系统_住宅小区物业管理系统分析与设计
- ni数据采集卡C语言API接口,NI数据采集卡
- 手机屏幕测试html,华为手机屏幕检测代码是什么
- rootkit后门程序开发测试过程
- 推荐1个易上手代码开源的好用的H5网页编辑工具
- oracle数据库timestamp类型显示问题(2099年和1999年)
- MacOS没有管理员账号的解决方法
- 2016..8.25 切题总结
- IObit Unlocker删除/解锁占用的文件