# How to pass 2 different timestamp in RangeFilterBuilder for elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778>\
**Category:** Elasticsearch\
**Created:** [January 22, 2015, 3:12pm UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778 "2015-01-22T15:12:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [January 22, 2015, 3:12pm UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/1 "2015-01-22T15:12:17Z")

</div>

Hi,

I'm currently using the below code to get avg value for every 30min from  
current time stamp. How can I pass 2 joda DateTime in this range filter to  
query between those timestamp ? Please let me know

```
public static Double searchAvgResultCPU(String esIndex, String esType,
    List<String> ipList) {
    String cpuMetricsQueryTime =
        MessageTranslator.getMessage("es.cpu_metrics.query.time");

    Iterator<String> i = ipList.iterator();
    logger.debug(GOT_THE_IP_LIST_AS + ipList);

    if (ipList.size() == 0) {
        logger.info(THE_IP_LIST_GOT_AS_EMPTY);
        return (double) 0;
    }
    else {
        logger.info("opening a es client connection to query..");
        Client client = ESClientFactory.getInstance();

        BoolQueryBuilder bqb = QueryBuilders.boolQuery();
        logger.info(MAKING_BOOL_QUERY_FOR_ALL_IP_LIST);
        while (i.hasNext()) {
            bqb.should(QueryBuilders.termQuery(ADDRESS, i.next()));
        }

```

_FilterBuilder fb =  
FilterBuilders.rangeFilter(TIMESTAMP).from( "now-" +  
cpuMetricsQueryTime).to("now");_

```
        SearchResponse response =
            client.prepareSearch(esIndex).setTypes(esType).setQuery(
                QueryBuilders.filteredQuery(bqb, fb)).setSize(20)
                .addAggregation(
                    AggregationBuilders.avg(CPU_AVERAGE).field(VALUE))
                .execute().actionGet();

        Avg avg = response.getAggregations().get(CPU_AVERAGE);
        Double averageValue = avg.getValue();

        if (averageValue.isNaN()) {
            logger.debug(THE_AVERAGE_VALUE_IS_RETURNED_AS
                + averageValue + RETURNING_0_AS_OUTPUT);
            return (double) 0;
        }

        logger.info(THE_AVERAGE_VALUE_RETURNED_IS + averageValue);
        return averageValue;
    }
}

```

Thanks,  
Subhadip

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ae3ec5f5-9bb1-44e0-b913-e42657af4afc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ae3ec5f5-9bb1-44e0-b913-e42657af4afc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [January 23, 2015, 5:17am UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/2 "2015-01-23T05:17:08Z")

</div>

Hi,

Any ideas?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 23, 2015, 9:49am UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/3 "2015-01-23T09:49:04Z")

</div>

Is your question about how I create a JODA DateTime object?  
Or how I pass it to the RangeFilter?

Sorry I did not get your question.

David

> Le 23 janv. 2015 à 06:17, Subhadip Bagui [i.bagui@gmail.com](mailto:i.bagui@gmail.com) a écrit :
> 
> Hi,
> 
> ## Any ideas?
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/815F69B1-3EA3-4FB8-A2F9-8E6E098E4EF3%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/815F69B1-3EA3-4FB8-A2F9-8E6E098E4EF3%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [January 24, 2015, 3:22pm UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/4 "2015-01-24T15:22:35Z")

</div>

Sorry, my question is how to pass 2 different Joda DateTime in  
RangeFilter. I'm trying to get an aggregated search result from es for  
every 5 min interval from current time till midnight to plot in graph.  
One way I think is to convert the DateTime in millis and pass it as long in  
RangeFilter's from() and to().

Is there any any better way?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 24, 2015, 3:53pm UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/5 "2015-01-24T15:53:28Z")

</div>

Not sure I understand but this is working:

QueryBuilder qb = filteredQuery(  
matchAllQuery(),  
rangeFilter("dateOfBirth").from(DateTime.parse("1940")).to(DateTime.parse("1950"))  
);

from and to use JODA DateTime here.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 24 janv. 2015 à 16:22, Subhadip Bagui [i.bagui@gmail.com](mailto:i.bagui@gmail.com) a écrit :
> 
> Sorry, my question is how to pass 2 different Joda DateTime in RangeFilter. I'm trying to get an aggregated search result from es for every 5 min interval from current time till midnight to plot in graph.  
> One way I think is to convert the DateTime in millis and pass it as long in RangeFilter's from() and to().
> 
> Is there any any better way?
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/BE3CF7A4-467A-4426-9669-5524076F87C7%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/BE3CF7A4-467A-4426-9669-5524076F87C7%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [January 26, 2015, 4:58pm UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/6 "2015-01-26T16:58:16Z")

</div>

Thanks David... I got the idea.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9dde6e20-3ec4-4a1e-929d-57acd29d467a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9dde6e20-3ec4-4a1e-929d-57acd29d467a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:36am UTC](https://discuss.elastic.co/t/how-to-pass-2-different-timestamp-in-rangefilterbuilder-for-elasticsearch/21778/7 "2017-07-06T00:36:37Z")

</div>


