Range query for dates with IN clause

How to query for a range of dates using the IN clause in Elastic Search? I am using Java Rest services.

I want to be able to query for timestamp for a range of dates? like timestamp in (list of dates)

Thanks

I think the only way currently to do that is by creating a boolean query and add each range query as an OR clause.

Thanks a lot, I do have other filters also, I have given the sample code below, I need to add the
filter for the range of dates also. Can you please guide? I tried adding should clause to it and it
fails

Thanks,

Kasi

BoolQueryBuilder boolQuery=QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(DP_FIELDS_FILTER_BY, filterBy))
.must(QueryBuilders.termQuery(DP_FIELDS_GROUP_BY, groupBy))
.must(QueryBuilders.termQuery(DP_FIELDS_OPERATIONS, operations));

Not sure if I have understood but adding a new boolean clause as part of your filters containing your range conditions might work:

BoolQueryBuilder boolQuery=QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(DP_FIELDS_FILTER_BY, filterBy))
.must(QueryBuilders.termQuery(DP_FIELDS_GROUP_BY, groupBy))
.must(QueryBuilders.termQuery(DP_FIELDS_OPERATIONS, operations));
BoolQueryBuilder rangeboolQuery=QueryBuilders.boolQuery();
// build or range query
.must(rangeboolQuery));

Thanks a lot, will give it a try

I tried it, does not work, have given below the JSON version of the query, this is what i added

for (LocalDateTime date:daysOfWeek) {

        LocalDateTime from = date.minusMinutes(15);
        LocalDateTime to = date.plusMinutes(15);
        boolQuery1.should(QueryBuilders.rangeQuery(DP_FIELDS_CALCULATED).from(Timestamp.valueOf(from).getTime()).to(Timestamp.valueOf(to).getTime()));
    }



    boolQuery.must(boolQuery1);

I verified data exists for the timestamp range in kibana

You will need to provide a reproducible example. I just tried myself and it works for me.

Can you please paste the query that you used as a reference?

Thanks,

Kasi

Probably will be moving to vertica from Elastic Search ..

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