@@ -10,16 +10,34 @@ match a query:
10
10
11
11
[source,js]
12
12
--------------------------------------------------
13
+ POST /sales/_search?size=0
13
14
{
14
15
"aggs" : {
15
- "author_count " : {
16
+ "type_count " : {
16
17
"cardinality" : {
17
- "field" : "author "
18
+ "field" : "type "
18
19
}
19
20
}
20
21
}
21
22
}
22
23
--------------------------------------------------
24
+ // CONSOLE
25
+ // TEST[setup:sales]
26
+
27
+ Response:
28
+
29
+ [source,js]
30
+ --------------------------------------------------
31
+ {
32
+ ...
33
+ "aggregations" : {
34
+ "type_count" : {
35
+ "value" : 3
36
+ }
37
+ }
38
+ }
39
+ --------------------------------------------------
40
+ // TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
23
41
24
42
==== Precision control
25
43
@@ -29,17 +47,20 @@ experimental[The `precision_threshold` option is specific to the current interna
29
47
30
48
[source,js]
31
49
--------------------------------------------------
50
+ POST /sales/_search?size=0
32
51
{
33
52
"aggs" : {
34
- "author_count " : {
53
+ "type_count " : {
35
54
"cardinality" : {
36
- "field" : "author_hash ",
55
+ "field" : "type ",
37
56
"precision_threshold": 100 <1>
38
57
}
39
58
}
40
59
}
41
60
}
42
61
--------------------------------------------------
62
+ // CONSOLE
63
+ // TEST[setup:sales]
43
64
44
65
<1> The `precision_threshold` options allows to trade memory for accuracy, and
45
66
defines a unique count below which counts are expected to be close to
@@ -159,40 +180,46 @@ however since hashes need to be computed on the fly.
159
180
160
181
[source,js]
161
182
--------------------------------------------------
183
+ POST /sales/_search?size=0
162
184
{
163
185
"aggs" : {
164
- "author_count " : {
186
+ "type_promoted_count " : {
165
187
"cardinality" : {
166
188
"script": {
167
189
"lang": "painless",
168
- "inline": "doc['author.first_name '].value + ' ' + doc['author.last_name '].value"
190
+ "inline": "doc['type '].value + ' ' + doc['promoted '].value"
169
191
}
170
192
}
171
193
}
172
194
}
173
195
}
174
196
--------------------------------------------------
197
+ // CONSOLE
198
+ // TEST[setup:sales]
175
199
176
200
This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax:
177
201
178
202
[source,js]
179
203
--------------------------------------------------
204
+ POST /sales/_search?size=0
180
205
{
181
206
"aggs" : {
182
- "author_count " : {
207
+ "type_promoted_count " : {
183
208
"cardinality" : {
184
209
"script" : {
185
210
"file": "my_script",
186
211
"params": {
187
- "first_name_field ": "author.first_name ",
188
- "last_name_field ": "author.last_name "
212
+ "type_field ": "type ",
213
+ "promoted_field ": "promoted "
189
214
}
190
215
}
191
216
}
192
217
}
193
218
}
194
219
}
195
220
--------------------------------------------------
221
+ // CONSOLE
222
+ // TEST[skip:no script]
196
223
197
224
TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
198
225
@@ -204,6 +231,7 @@ had a value.
204
231
205
232
[source,js]
206
233
--------------------------------------------------
234
+ POST /sales/_search?size=0
207
235
{
208
236
"aggs" : {
209
237
"tag_cardinality" : {
@@ -215,5 +243,6 @@ had a value.
215
243
}
216
244
}
217
245
--------------------------------------------------
218
-
246
+ // CONSOLE
247
+ // TEST[setup:sales]
219
248
<1> Documents without a value in the `tag` field will fall into the same bucket as documents that have the value `N/A`.
0 commit comments