1.mappingPUT user_behavior { "mappings": { "user_behavior": { "properties": { "date": { "type": "createDate", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } } } 2.实体@Data@Document(indexName = "user_behavior", type = "user_behavior")public class UserBehavior implements Serializable{ private String createDate = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");}3.insertIndexQuery indexQuery = new IndexQueryBuilder().withObject(userBehavior).build(); elasticsearchTemplate.index(indexQuery); 4.queryBoolQueryBuilder queryBld = QueryBuilders.boolQuery(); queryBld.must(QueryBuilders.rangeQuery("createDate").gt("2018-06-22 17:00:00").lt("2018-06-22 17:51:00")); NativeSearchQueryBuilder nativeQueryBuilder = new NativeSearchQueryBuilder().withQuery(queryBld); SearchQuery searchQuery = nativeQueryBuilder.build(); Listbehaviors = elasticsearchTemplate.queryForList(searchQuery, UserBehavior.class); System.out.println(behaviors.size()); System.out.println(behaviors.get(0).getCreateDate());