I have documents such as:
{
{id:1, timestamp:123456897} ,
{id:1, timestamp:123456893},
{id:1, timestamp:123356897}
}
Suppose I need to get highest time stamp for each id ? (assuming there can be multiple ids and each id has multiple timestamps.)
SQL query can be:
SELECT id, max(timestamp) FROM table GROUP BY id;
Can some one please help ?
@dadoonet - Could you please help ? Many Thanks, ~Kedar
rockybean
(Rockybean)
October 4, 2017, 4:21pm
3
Just do a simple test and it seems that this can solve your problem. Give it a try!
PUT test_max/data/1
{
"id":1,
"timestamp":[10,23,23]
}
PUT test_max/data/2
{
"id":1,
"timestamp":[10,232,23]
}
GET test_max/data/_search
{
"size":1,
"aggs": {
"a": {
"terms": {
"field": "id",
"size": 10
},
"aggs": {
"max": {
"max": {
"field": "timestamp"
}
}
}
}
}
}
By the way, you should use update by script to update the document because timestamp
field is an array type.
rockybean
(Rockybean)
October 4, 2017, 4:24pm
4
If your document is like below, just use the query I give above.
{id:1, timestamp:123456897} ,
{id:1, timestamp:123456893},
{id:1, timestamp:123356897}
The query is like below.
GET test_max/data/_search
{
"size":1,
"aggs": {
"a": {
"terms": {
"field": "id",
"size": 10
},
"aggs": {
"max": {
"max": {
"field": "timestamp"
}
}
}
}
}
}
dadoonet
(David Pilato)
October 4, 2017, 6:35pm
5
Please don't ping people like this.
Please read
The heart of the free and open Elastic Stack
Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease.
PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST
Some useful links:
elasticsearch reference guide
elasticsearch user guide
elasticsearch plugins
elasticsearch cl…
Specifically the "be patient" part.
I am sorry @dadoonet . I will take care going forward!
thanks @rockybean , I am using java APIs to pull the data, could you please help me in making use of them for above queries ? Thanks!
rockybean
(Rockybean)
October 4, 2017, 11:44pm
8
Thanks, It is not helpful actually. Can you please help me with better option ?
Hi Can some one please help ?
system
(system)
Closed
November 6, 2017, 6:32am
12
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.