企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
对象中设置得为 Date, Field 设置为 Long, 生成的elasticsearch 是 Long, 返回为前端时,格式化成字符串的日期格式即可 ``` /**成立日期*/ @Field(type = FieldType.Long, format = DateFormat.basic_date) @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd") @DateTimeFormat(pattern="yyyy-MM-dd") private Date registrationDate; ``` ``` BoolQueryBuilder builder = QueryBuilders.boolQuery(); // 成立年限, elasticsearch 中 是long 类型, 前端传的是以月份分割 "12-36", "36-60" List<String> registrationDate = bo.getRegistrationDate(); if (registrationDate != null && !registrationDate.isEmpty()) { BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); registrationDate.forEach(data -> { String[] split = data.split(StrUtil.DASHED); LocalDate now = LocalDate.now(); LocalDate minLocalDate = now.minusMonths(Long.parseLong(split[1])); LocalDate maxLocalDate = now.minusMonths(Long.parseLong(split[0])); long minMilli = minLocalDate.atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli(); long maxMilli = maxLocalDate.atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli(); RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(REGISTRATION_DATE).gte(minMilli).lte(maxMilli); // 多条使用 should (or) boolQueryBuilder.should(rangeQueryBuilder); }); builder.must(boolQueryBuilder); } ```