You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 300_Aggregations/35_date_histogram.asciidoc
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,41 @@
1
1
2
-
== Looking at time
2
+
== Looking at Time
3
3
4
4
If search is the most popular activity in Elasticsearch, building date
5
5
histograms must be the second most popular.((("date histograms, building")))((("histograms", "building date histograms")))((("aggregations", "building date histograms from"))) Why would you want to use a date
6
6
histogram?
7
7
8
-
Imagine your data has a timestamp.((("time, analytics over", id="ix_timeanalyze"))) It doesn't matter what the data is -- Apache
9
-
log events, stock buy/sell transaction dates, baseball game times
10
-
-- anything with a timestamp can benefit from the date histogram. When you have
11
-
a timestamp, you often want to build metrics which are expressed _over time_.
8
+
Imagine your data has a timestamp.((("time, analytics over", id="ix_timeanalyze"))) It doesn't matter what the data is--Apache
9
+
log events, stock buy/sell transaction dates, baseball game times--anything with a timestamp can benefit from the date histogram. When you have
10
+
a timestamp, you often want to build metrics that are expressed _over time_:
12
11
13
12
- How many cars sold each month this year?
14
13
- What was the price of this stock for the last 12 hours?
15
14
- What was the average latency of our website every hour in the last week?
16
15
17
16
While regular histograms are often represented as bar charts, date histograms
18
17
tend to be converted into line graphs representing time series.((("analytics", "over time"))) Many
19
-
companies use Elasticsearch _solely_ for analytics over time-
20
-
series data. The `date_histogram` bucket is their bread and butter.
18
+
companies use Elasticsearch _solely_ for analytics over time series data. The `date_histogram` bucket is their bread and butter.
21
19
22
-
The `date_histogram` bucket works((("buckets", "date_histogram"))) very similar to the regular `histogram`. Rather
20
+
The `date_histogram` bucket works((("buckets", "date_histogram"))) similarly to the regular `histogram`. Rather
23
21
than building buckets based on a numeric field representing numeric ranges,
24
-
it builds buckets based on a time ranges. Each bucket is therefore defined as a
25
-
certain calendar size (e.g. `1 month` or `2.5 days`, etc).
22
+
it builds buckets based on time ranges. Each bucket is therefore defined as a
23
+
certain calendar size (for example, `1 month` or `2.5 days`).
26
24
27
-
.Can a regular histogram work with dates?
25
+
.Can a Regular Histogram Work with Dates?
28
26
****
29
27
Technically, yes.((("histogram bucket", "dates and"))) A regular `histogram` bucket will work with dates. However,
30
28
it is not calendar-aware. With the `date_histogram`, you can specify intervals
31
29
such as `1 month`, which knows that February is shorter than December. The
32
-
`date_histogram` also has the advantage of being able to work with timezones,
33
-
which allows you to customize graphs to the timezone of the user, not the server.
30
+
`date_histogram` also has the advantage of being able to work with time zones,
31
+
which allows you to customize graphs to the time zone of the user, not the server.
34
32
35
33
The regular histogram will interpret dates as numbers, which means you must specify
36
34
intervals in terms of milliseconds. And the aggregation doesn't know about
37
35
calendar intervals, which makes it largely useless for dates.
38
36
****
39
37
40
-
Our first example ((("line charts, building from aggregations")))will build a simple line chart to answer the question:
38
+
Our first example ((("line charts, building from aggregations")))will build a simple line chart to answer this question:
41
39
how many cars were sold each month?
42
40
43
41
[source,js]
@@ -56,13 +54,13 @@ GET /cars/transactions/_search?search_type=count
0 commit comments