Elasticsearch filter query with time range using java api

Hi,

I have a document like below

{
"_index": "cpu_usage_metrics",
"_type": "cpu_usage_metrics",
"_id": "CKAAs1n8TKiR6FncC5NLGA",
"_score": 1,
"_source": {
"status": 0,
"occurrences": 1,
"value": "33",
"key": "vm.server2.cpu.usage",
"client": "vm.server2",
"@timestamp": "2014-06-03T20:18:19+05:30",
"check_name": "cpu_usage_metrics",
"address": "10.203.238.138",
"command": "cpu-usage-metrics.sh"
}
}

I want to do a filtered query with time range using java api like below

"filter": {
"range": {
"@timestamp": {
"to": "now",
"from": "now - 5mins"
}
}
}

Please suggest how to form the Filter in java api.

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/f596658e-5ec4-42ac-abc1-4f99416be101%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hey,

did you try something along the
lines FilterBuilders.rangeFilter("@timestamp").from("now").to("now - 5d") -
did that pose problems?

make sure you are reading this paragraph about date range filters:

--Alex

On Wed, Jun 4, 2014 at 1:43 PM, Subhadip Bagui i.bagui@gmail.com wrote:

Hi,

I have a document like below

{
"_index": "cpu_usage_metrics",
"_type": "cpu_usage_metrics",
"_id": "CKAAs1n8TKiR6FncC5NLGA",
"_score": 1,
"_source": {
"status": 0,
"occurrences": 1,
"value": "33",
"key": "vm.server2.cpu.usage",
"client": "vm.server2",
"@timestamp": "2014-06-03T20:18:19+05:30",
"check_name": "cpu_usage_metrics",
"address": "10.203.238.138",
"command": "cpu-usage-metrics.sh"
}
}

I want to do a filtered query with time range using java api like below

"filter": {
"range": {
"@timestamp": {
"to": "now",
"from": "now - 5mins"
}
}
}

Please suggest how to form the Filter in java api.

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/f596658e-5ec4-42ac-abc1-4f99416be101%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/f596658e-5ec4-42ac-abc1-4f99416be101%40googlegroups.com?utm_medium=email&utm_source=footer
.
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/CAGCwEM_YymPLyoy2nVmk9VAeq2RFHu7mJtufhBHCGd5Q6u9ZUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi Alex,

Yes I tried that and it's working. Thanks :slight_smile:

--
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/8addde47-a57b-4a4a-aa7a-68b419bcf90e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.