Is there any way to implement SQL window functions?
Here is my use case:
Multiple events reported with "Type" and "Timestamp" fields. I'm looking for a way to extract the latest occurrence of each type.
In SQL this can be easily achieved:
This is how my data looks like:
..and this is the desired output:
The following query achieves just that:
SELECT [Type],[Description] FROM (
SELECT
ROW_NUMBER() OVER (PARTITION BY [Type] ORDER BY [Timestamp] DESC) AS [RowNumber],
[Type],
[Description]
FROM [test]
) T
WHERE T.[RowNumber] = 1
Yeah, I know Elastic is not a relational database. However, I was hoping this is feasible and I'm just unable to find out how...
It looks like you are looking for the latest of each type. If yes, in this case do something similar to the link below and use "max" instead of "avg" on "timestamp" field.
I should point out that pipeline aggregations offer somewhat window function like functionality. I haven't read the rest of the post because it looks like you have it covered so I'm not sure if they fit what you want. But they are a thing.
Thanks guys, it looks like I don't have a choice but to implement my own logic to fetch this.
Hoped I'll get away with just one query to avoid implementing a middle tier...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.