String script = "doc['createtime'].value";
Script script1 = new Script(script);
SortBuilder sortBuilder_by_date = SortBuilders.scriptSort(script1,
ScriptSortBuilder.ScriptSortType.STRING).order(SortOrder.DESC);
//分页查询
SearchRequestBuilder searchRequestBuilder = esTemplate.getClient()
.prepareSearch(index)
.setTypes(type)
.setScroll(new TimeValue(30000))
.setSize(Integer.valueOf(pageSize));
if (!aggsisnull)
builder.aggregation(aggs);
if (!queryisnull)
builder.query(query).sort(sortBuilder_by_date);
searchRequestBuilder.setSource(builder);
参考链接:
https://blog.csdn.net/qq_28834355/article/details/109050305