How to pass 2 different timestamp in RangeFilterBuilder for elasticsearch

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ae3ec5f5-9bb1-44e0-b913-e42657af4afc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0484e9f6-8f63-42fb-ad9d-2d3ec1629ce3%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/815F69B1-3EA3-4FB8-A2F9-8E6E098E4EF3%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a2e98534-87ad-47bb-8f3f-cc8b9fad8629%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs

Le 24 janv. 2015 à 16:22, Subhadip Bagui 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.
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?utm_medium=email&utm_source=footer.
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/BE3CF7A4-467A-4426-9669-5524076F87C7%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9dde6e20-3ec4-4a1e-929d-57acd29d467a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.