Records in my database every 5 minutes. And even after filtering by an interval, it gives me the same records from the database. Maybe I'm doing something wrong?
I will be very grateful for the answer.
Can you please explain what you are trying to achieve at a high level? Aggregation allow you to perform calculations over your data, e.g. provide a date histogram with the maximum and minimum price per day or week. Is that what you are looking to do?
I have a database with 100k records and I want only every 50th record to be displayed.
That is, a database with a 5-minute timeframe, bitcoin price rates. I need to display points for the chart for the last year/month/week. At the same time, so that there are no more than 1000 results. Since the graphic chart cannot render more points.
Unfortunately, there are problems with that. I thought that I need to use other methods.
It turns out that what you recommended in that thread is what you need. But it doesn't work right for me.
For example, i have 5 records:
PUT /coin_charts/_search
{
"_source": {
"priceUsd": 45000,
"time": 1642716000000, //Just in case, I will clarify that I am aware of the same milliseconds. I just added a date field in a new clean database in order to experiment with it.
"date": "2022-01-01T16:23:09.55"
}
},
{
"_source": {
"priceUsd": 43000,
"time": 1642716000000,
"date": "2022-01-02T16:23:09.55"
}
},
{
"_source": {
"priceUsd": 40000,
"time": 1642716000000,
"date": "2022-01-03T16:23:09.55"
}
},
{
"_source": {
"priceUsd": 38000,
"time": 1642716000000,
"date": "2022-01-04T16:23:09.55"
}
},
{
"_source": {
"priceUsd": 36000,
"time": 1642716000000,
"date": "2022-01-05T16:23:09.55"
}
}
And for interval i'm use:
POST /coin_charts/_doc/_search
{
"aggs": {
"bitcoin": {
"date_histogram": {
"field": "date",//I tried to use first a field with milliseconds(time), it didn't work, then I decided to add a field with a date
"fixed_interval": "2d"
}
}
}
}
I thought this should only print two results from my database (1 and 3), but it prints all 5 results. Maybe I'm wrote the request incorrectly?
There are two types of aggregation: bucket
aggregations and metrics aggregation. Please see the documents to get detail. Bucket aggregation such as date histogram bucket aggregation only divide all documents into some buckets and did not select them. You can use metrics aggregations such as top hits or top metrics aggregation to retrieve some value or documents from each packets.
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.