Skip to content

Commit 4b16681

Browse files
pengqiuyuanmedcl
authored andcommitted
chapter22_part5:/300_Aggregations/30_histogram.asciidoc (#295)
* chapter22_part5:/300_Aggregations/30_histogram.asciidoc 初译 * chapter22_part5:/300_Aggregations/30_histogram.asciidoc 第一行:[[_building_bar_charts]] * chapter22_part5:/300_Aggregations/30_histogram.asciidoc 移除多余前缀 * chapter22_part5:/300_Aggregations/30_histogram.asciidoc 按 review 意见修改。感谢 @smilesfc * chapter22_part5:/300_Aggregations/30_histogram.asciidoc 按 review 意见修改。感谢 @qindongliang * chapter22_part5:/300_Aggregations/30_histogram.asciidoc 按照 review 意见修改。
1 parent a37ed90 commit 4b16681

File tree

1 file changed

+23
-46
lines changed

1 file changed

+23
-46
lines changed

300_Aggregations/30_histogram.asciidoc

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1+
[[_building_bar_charts]]
2+
== 条形图
13

2-
== Building Bar Charts
4+
聚合还有一个令人激动的特性就是能够十分容易地将它们转换成图表和图形。((("bar charts, building from aggregations", id="ix_barcharts", range="startofrange")))((("aggregations", "building bar charts from")))本章中,
5+
我们正在通过示例数据来来完成各种各样的聚合分析,最终,我们将会发现聚合功能是非常强大的。
36

4-
One of the exciting aspects of aggregations are how easily they are converted
5-
into charts and graphs.((("bar charts, building from aggregations", id="ix_barcharts", range="startofrange")))((("aggregations", "building bar charts from"))) In this chapter, we are focusing
6-
on various analytics that we can wring out of our example dataset. We will also
7-
demonstrate the types of charts aggregations can power.
7+
直方图 ++histogram++ 特别有用。((("buckets", "histogram")))((("histogram bucket")))((("histograms"))) 它本质上是一个条形图,如果有创建报表或分析仪表盘的经验,那么我们会毫无疑问的发现里面有一些图表是条形图。
8+
创建直方图需要指定一个区间,如果我们要为售价创建一个直方图,可以将间隔设为 20,000。这样做将会在每个 $20,000 档创建一个新桶,然后文档会被分到对应的桶中。
89

9-
The ++histogram++ bucket is particularly useful.((("buckets", "histogram")))((("histogram bucket")))((("histograms"))) Histograms are essentially
10-
bar charts, and if you've ever built a report or analytics dashboard, you
11-
undoubtedly had a few bar charts in it. The histogram works by specifying an interval. If we were histogramming sale
12-
prices, you might specify an interval of 20,000. This would create a new bucket
13-
every $20,000. Documents are then sorted into buckets.
10+
对于仪表盘来说,我们希望知道每个售价区间内汽车的销量。我们还会想知道每个售价区间内汽车所带来的收入,可以通过对每个区间内已售汽车的售价求和得到。
1411

15-
For our dashboard, we want to know how many cars sold in each price range. We
16-
would also like to know the total revenue generated by that price bracket. This is
17-
calculated by summing the price of each car sold in that interval.
18-
19-
To do this, we use a `histogram` and a nested `sum` metric:
12+
可以用 `histogram` 和一个嵌套的 `sum` 度量得到我们想要的答案:
2013

2114
[source,js]
2215
--------------------------------------------------
@@ -41,23 +34,17 @@ GET /cars/transactions/_search
4134
}
4235
--------------------------------------------------
4336
// SENSE: 300_Aggregations/30_histogram.json
44-
<1> The `histogram` bucket requires two parameters: a numeric field, and an
45-
interval that defines the bucket size.
37+
<1> `histogram` 桶要求两个参数:一个数值字段以及一个定义桶大小间隔。
4638
// Mention use of "size" to get back just the top result?
47-
<2> A `sum` metric is nested inside each price range, which will show us the
48-
total revenue for that bracket
39+
<2> `sum` 度量嵌套在每个售价区间内,用来显示每个区间内的总收入。
4940

50-
As you can see, our query is built around the `price` aggregation, which contains
51-
a `histogram` bucket. This bucket requires a numeric field to calculate
52-
buckets on, and an interval size. The interval defines how "wide" each bucket
53-
is. An interval of 20000 means we will have the ranges `[0-19999, 20000-39999, ...]`.
41+
如我们所见,查询是围绕 `price` 聚合构建的,它包含一个 `histogram` 桶。它要求字段的类型必须是数值型的同时需要设定分组的间隔范围。
42+
间隔设置为 20,000 意味着我们将会得到如 `[0-19999, 20000-39999, ...]` 这样的区间。
5443

55-
Next, we define a nested metric inside the histogram. This is a `sum` metric, which
56-
will sum up the `price` field from each document landing in that price range.
57-
This gives us the revenue for each price range, so we can see if our business
58-
makes more money from commodity or luxury cars.
44+
接着,我们在直方图内定义嵌套的度量,这个 `sum` 度量,它会对落入某一具体售价区间的文档中 `price` 字段的值进行求和。
45+
这可以为我们提供每个售价区间的收入,从而可以发现到底是普通家用车赚钱还是奢侈车赚钱。
5946

60-
And here is the response:
47+
响应结果如下:
6148

6249
[source,js]
6350
--------------------------------------------------
@@ -93,30 +80,23 @@ And here is the response:
9380
}
9481
--------------------------------------------------
9582

96-
The response is fairly self-explanatory, but it should be noted that the
97-
histogram keys correspond to the lower boundary of the interval. The key `0`
98-
means `0-19,999`, the key `20000` means `20,000-39,999`, and so forth.
83+
结果很容易理解,不过应该注意到直方图的键值是区间的下限。键 `0` 代表区间 `0-19,999` ,键 `20000` 代表区间 `20,000-39,999` ,等等。
9984

10085
[NOTE]
10186
=====================
102-
You'll notice that empty intervals, such as $40,000-60,000, is missing in the
103-
response. The `histogram` bucket omits these by default, since it could lead
104-
to the unintended generation of potentially enormous output.
87+
我们可能会注意到空的区间,比如:$40,000-60,000,没有出现在响应中。 `histogram` 桶默认会忽略它,因为它有可能会导致不希望的潜在错误输出。
10588
106-
We'll discuss how to include empty buckets in the next section, <<_returning_empty_buckets>>.
89+
我们会在下一小节中讨论如何包括空桶。返回空桶 <<_returning_empty_buckets>>
10790
=====================
10891

109-
Graphically, you could represent the preceding data in the histogram shown in <<barcharts-histo1>>.
92+
可以在图 <<barcharts-histo1>> 中看到以上数据直方图的图形化表示。
11093

11194
[[barcharts-histo1]]
11295
.Sales and Revenue per price bracket
11396
image::images/elas_28in01.png["Sales and Revenue per price bracket"]
11497

115-
Of course, you can build bar charts with any aggregation that emits categories
116-
and statistics, not just the `histogram` bucket. Let's build a bar chart of the
117-
top 10 most popular makes, and their average price, and then calculate the standard
118-
error to add error bars on our chart. This will use the `terms` bucket and
119-
an `extended_stats` ((("extended_stats metric")))metric:
98+
当然,我们可以为任何聚合输出的分类和统计结果创建条形图,而不只是 `直方图` 桶。让我们以最受欢迎 10 种汽车以及它们的平均售价、标准差这些信息创建一个条形图。
99+
我们会用到 `terms` 桶和 `extended_stats` ((("extended_stats metric")))度量:
120100

121101
[source,js]
122102
----
@@ -141,20 +121,17 @@ GET /cars/transactions/_search
141121
}
142122
----
143123

144-
This will return a list of makes (sorted by popularity) and a variety of statistics
145-
about each. In particular, we are interested in `stats.avg`, `stats.count`,
146-
and `stats.std_deviation`. Using((("standard error, calculating"))) this information, we can calculate the standard error:
124+
上述代码会按受欢迎度返回制造商列表以及它们各自的统计信息。我们对其中的 `stats.avg` 、 `stats.count` 和 `stats.std_deviation` 信息特别感兴趣,并用 ((("standard error, calculating"))) 它们计算出标准差:
147125

148126
................................
149127
std_err = std_deviation / count
150128
................................
151129

152-
This will allow us to build a chart like <<barcharts-bar1>>.
130+
创建图表如图 <<barcharts-bar1>>
153131

154132
[[barcharts-bar1]]
155133
.Average price of all makes, with error bars
156134
image::images/elas_28in02.png["Average price of all makes, with error bars"]
157135

158136

159137
((("bar charts, building from aggregations", range="endofrange", startref="ix_barcharts")))
160-

0 commit comments

Comments
 (0)