jar包版本:5.6.0
代码片段:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Script script = new Script("7 == doc['sortStatus'].value && 6 == doc['sortStatus'].value ? '1' : '0'");
ScriptSortBuilder order = new ScriptSortBuilder(script, NUMBER).order(SortOrder.DESC);
searchSourceBuilder.sort(order);
错误信息:
{"error":{"root_cause":[{"type":"script_parse_exception","reason":"unexpected field [source]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"owhat","node":"3YNiUcFRRMCi5EH04LnrXA","reason":{"type":"script_parse_exception","reason":"unexpected field [source]"}}]},"status":500}
实际执行脚本:
{
"from": 0,
"size": 10,
"sort": [
{
"_script": {
"script": {
"source": "7 == doc['sortStatus'].value && 6 == doc['sortStatus'].value ? 1 : 0",
"lang": "painless"
},
"type": "number",
"order": "desc"
}
}
]
}
现象:
直接引用脚本符合查询可以正常查询结果,代码执行不可以
代码片段:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
Script script = new Script("7 == doc['sortStatus'].value && 6 == doc['sortStatus'].value ? '1' : '0'");
ScriptSortBuilder order = new ScriptSortBuilder(script, NUMBER).order(SortOrder.DESC);
searchSourceBuilder.sort(order);
错误信息:
{"error":{"root_cause":[{"type":"script_parse_exception","reason":"unexpected field [source]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"owhat","node":"3YNiUcFRRMCi5EH04LnrXA","reason":{"type":"script_parse_exception","reason":"unexpected field [source]"}}]},"status":500}
实际执行脚本:
{
"from": 0,
"size": 10,
"sort": [
{
"_script": {
"script": {
"source": "7 == doc['sortStatus'].value && 6 == doc['sortStatus'].value ? 1 : 0",
"lang": "painless"
},
"type": "number",
"order": "desc"
}
}
]
}
现象:
直接引用脚本符合查询可以正常查询结果,代码执行不可以
1 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
代码部分写的转成dsl打印下,看是否完全一致。
从这个角度进行排查。