我试图修改此painless script,以便我可以从嵌套结构中检索MAX日期。
假装我有这样的映射:
{
"mappings": {
"hello": {
"properties": {
"field1": {"type" : "date", "format" : "yyyy-MM-dd HH:mm:ss"},
"field2": {"type" : "date", "format" : "yyyy-MM-dd HH:mm:ss"},
"test": { "type": "nested",
"properties": {
"field3": {"type" : "date", "format" : "yyyy-MM-dd HH:mm:ss"},
"field4": {"type": "integer"},
"test2": { "type": "nested",
"properties": {
"field5": {"type" : "date", "format" : "yyyy-MM-dd HH:mm:ss"}
}
}
}
}
}
}
}
}
我想要做的是从test.field3
中检索MAX日期我尝试过以下几件事:
Date maxDate
for (int i = 0; i < params._source['test'].size(); i++) {
if (params._source['test'][i].field3 > score) {
maxDate= params._source['test'][i].field3
}
} return maxDate
任何帮助都会非常有帮助!我感觉我遇到了日期解析问题,但也许我错了。
如果有人感觉游戏,这里有一份文件:
{
"field1" : "2018-01-02 10:00:00",
"field2" : "2018-01-04 10:00:00",
"test": [
{
"field3": "2018-01-04 10:00:00",
"field6": 1,
"test2": [{
"field4": "2018-01-04 10:00:00"
}
]
}
]
}
答案 0 :(得分:2)
我会用Java 8 Streams
这样做if (mCursor!=null && mCursor.moveToFirst()) {
delete = db.delete(SchemeShapes.Shape.TABLE_NAME, SchemeShapes.Shape.ID + "= ?", new String[]{String.valueOf(shapeID)});
}