Skip to content

Commit aafa590

Browse files
committed
Edited 300_Aggregations/35_date_histogram.asciidoc with Atlas code editor
1 parent 3181047 commit aafa590

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

300_Aggregations/35_date_histogram.asciidoc

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11

2-
== Looking at time
2+
== Looking at Time
33

44
If search is the most popular activity in Elasticsearch, building date
55
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
66
histogram?
77

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_:
1211

1312
- How many cars sold each month this year?
1413
- What was the price of this stock for the last 12 hours?
1514
- What was the average latency of our website every hour in the last week?
1615

1716
While regular histograms are often represented as bar charts, date histograms
1817
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.
2119

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
2321
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`).
2624

27-
.Can a regular histogram work with dates?
25+
.Can a Regular Histogram Work with Dates?
2826
****
2927
Technically, yes.((("histogram bucket", "dates and"))) A regular `histogram` bucket will work with dates. However,
3028
it is not calendar-aware. With the `date_histogram`, you can specify intervals
3129
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.
3432
3533
The regular histogram will interpret dates as numbers, which means you must specify
3634
intervals in terms of milliseconds. And the aggregation doesn't know about
3735
calendar intervals, which makes it largely useless for dates.
3836
****
3937

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:
4139
how many cars were sold each month?
4240

4341
[source,js]
@@ -56,13 +54,13 @@ GET /cars/transactions/_search?search_type=count
5654
}
5755
--------------------------------------------------
5856
// SENSE: 300_Aggregations/35_date_histogram.json
59-
<1> The interval is requested in calendar terminology (e.g. one month per bucket)
57+
<1> The interval is requested in calendar terminology (for example, one month per bucket).
6058
// "pretty"-> "readable by humans". mention that otherwise get back ms-since-epoch?
61-
<2> We provide a date format so that bucket keys are pretty
59+
<2> We provide a date format so that bucket keys are pretty.
6260

6361
Our query has a single aggregation, which builds a bucket
6462
per month. This will give us the number of cars sold in each month. An additional
65-
"format" parameter is provided so that the buckets have "pretty" keys. Internally,
63+
format" parameter is provided so that the buckets have "pretty" keys. Internally,
6664
dates are simply represented as a numeric value. This tends to make UI designers
6765
grumpy, however, so a prettier format can be specified using common date formatting.
6866

0 commit comments

Comments
 (0)