Date range java api examples

Hi, I am trying to search the documents using a date range filter along with some keywords. I couldn't find any java api samples to do so. Could you please help me.
Normal search works with the following code: But am after a date range filter search.

 SearchResponse<JsonNode> search = -> s
                        .query(q -> q
                                .match(f -> f.field(searchKey).query(searchValue).fuzziness(fuzziness).operator(Operator.And))),

version details:


Following code works. Please suggest if there is any better option.

        final String json = "{ \"fld_date\": {\"gte\": \"2018-02-02T15:08:28Z\", \"lte\": \"2021-06-23T11:35:01.120Z\"}}";
        final JsonpMapper mapper = new JsonbJsonpMapper();
        final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
        final JsonData data = JsonData.from(parser, mapper);
        final JsonValue value = data.toJson(mapper);
        SearchResponse<JsonNode> search = -> s
                .query( q -> q.range(value)), JsonNode.class);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.