mapping:
{
"_doc": {
"properties": {
"pauseTime": {
"format": "yyyy-MM-dd HH:mm:ss",
"type": "date_range"
}
}
}
}
对应的javabean:
public class DateRange {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date gte;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date lte;
}
现在要按此字段做一个排序(此字段不为空且在当期前时间端内的)
HashMap<String, Object> params = new HashMap<>();
params.put("nowTime", System.currentTimeMillis());
Script script =new Script(ScriptType.INLINE, "painless",
"if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){" +
"return 1;" +
"}else{" +
"return 0;" +
"}",params);
ScriptSortBuilder pauseTime = SortBuilders.scriptSort(script, ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.DESC);
执行报异常:
"failed_shards": [
{
"shard": 0,
"index": "XXXXXX",
"node": "hzMEDqXeQ8mzhKlGu3exkA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){",
" ^---- HERE"
],
"script": "if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){return 1;}else{return 0;}",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
{
"_doc": {
"properties": {
"pauseTime": {
"format": "yyyy-MM-dd HH:mm:ss",
"type": "date_range"
}
}
}
}
对应的javabean:
public class DateRange {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date gte;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date lte;
}
现在要按此字段做一个排序(此字段不为空且在当期前时间端内的)
HashMap<String, Object> params = new HashMap<>();
params.put("nowTime", System.currentTimeMillis());
Script script =new Script(ScriptType.INLINE, "painless",
"if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){" +
"return 1;" +
"}else{" +
"return 0;" +
"}",params);
ScriptSortBuilder pauseTime = SortBuilders.scriptSort(script, ScriptSortBuilder.ScriptSortType.NUMBER).order(SortOrder.DESC);
执行报异常:
"failed_shards": [
{
"shard": 0,
"index": "XXXXXX",
"node": "hzMEDqXeQ8mzhKlGu3exkA",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){",
" ^---- HERE"
],
"script": "if(ctx.pauseTime!=null && ctx.pauseTime.gte.value.millis<params.nowTime && ctx.pauseTime.lte.value.millis<params.nowTime){return 1;}else{return 0;}",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
0 个回复