Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 3b766ee

Browse files
author
ashwinkumar12345
committed
Merge branch 'index_rollup_walkthrough'
2 parents bbc15ae + f95dd60 commit 3b766ee

File tree

1 file changed

+368
-0
lines changed

1 file changed

+368
-0
lines changed

docs/im/index-rollups/index.md

Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,371 @@ GET target_index/_search
8787
```
8888

8989
Consider a scenario where you collect rolled up data from 1 PM to 9 PM in hourly intervals and live data from 7 PM to 11 PM in minutely intervals. If you execute an aggregation over these in the same query, for 7 PM to 9 PM, you see an overlap of both rolled up data and live data because they get counted twice in the aggregations.
90+
91+
## Sample Walkthrough
92+
93+
This walkthrough uses the Kibana sample e-commerce data. To add that sample data, log in to Kibana, choose **Home** and **Try our sample data**. For **Sample eCommerce orders**, choose **Add data**.
94+
95+
Then run a search:
96+
97+
```json
98+
GET kibana_sample_data_ecommerce/_search
99+
```
100+
101+
#### Sample response
102+
103+
```json
104+
{
105+
"took": 23,
106+
"timed_out": false,
107+
"_shards": {
108+
"total": 1,
109+
"successful": 1,
110+
"skipped": 0,
111+
"failed": 0
112+
},
113+
"hits": {
114+
"total": {
115+
"value": 4675,
116+
"relation": "eq"
117+
},
118+
"max_score": 1,
119+
"hits": [
120+
{
121+
"_index": "kibana_sample_data_ecommerce",
122+
"_type": "_doc",
123+
"_id": "jlMlwXcBQVLeQPrkC_kQ",
124+
"_score": 1,
125+
"_source": {
126+
"category": [
127+
"Women's Clothing",
128+
"Women's Accessories"
129+
],
130+
"currency": "EUR",
131+
"customer_first_name": "Selena",
132+
"customer_full_name": "Selena Mullins",
133+
"customer_gender": "FEMALE",
134+
"customer_id": 42,
135+
"customer_last_name": "Mullins",
136+
"customer_phone": "",
137+
"day_of_week": "Saturday",
138+
"day_of_week_i": 5,
139+
"email": "[email protected]",
140+
"manufacturer": [
141+
"Tigress Enterprises"
142+
],
143+
"order_date": "2021-02-27T03:56:10+00:00",
144+
"order_id": 581553,
145+
"products": [
146+
{
147+
"base_price": 24.99,
148+
"discount_percentage": 0,
149+
"quantity": 1,
150+
"manufacturer": "Tigress Enterprises",
151+
"tax_amount": 0,
152+
"product_id": 19240,
153+
"category": "Women's Clothing",
154+
"sku": "ZO0064500645",
155+
"taxless_price": 24.99,
156+
"unit_discount_amount": 0,
157+
"min_price": 12.99,
158+
"_id": "sold_product_581553_19240",
159+
"discount_amount": 0,
160+
"created_on": "2016-12-24T03:56:10+00:00",
161+
"product_name": "Blouse - port royal",
162+
"price": 24.99,
163+
"taxful_price": 24.99,
164+
"base_unit_price": 24.99
165+
},
166+
{
167+
"base_price": 10.99,
168+
"discount_percentage": 0,
169+
"quantity": 1,
170+
"manufacturer": "Tigress Enterprises",
171+
"tax_amount": 0,
172+
"product_id": 17221,
173+
"category": "Women's Accessories",
174+
"sku": "ZO0085200852",
175+
"taxless_price": 10.99,
176+
"unit_discount_amount": 0,
177+
"min_price": 5.06,
178+
"_id": "sold_product_581553_17221",
179+
"discount_amount": 0,
180+
"created_on": "2016-12-24T03:56:10+00:00",
181+
"product_name": "Snood - rose",
182+
"price": 10.99,
183+
"taxful_price": 10.99,
184+
"base_unit_price": 10.99
185+
}
186+
],
187+
"sku": [
188+
"ZO0064500645",
189+
"ZO0085200852"
190+
],
191+
"taxful_total_price": 35.98,
192+
"taxless_total_price": 35.98,
193+
"total_quantity": 2,
194+
"total_unique_products": 2,
195+
"type": "order",
196+
"user": "selena",
197+
"geoip": {
198+
"country_iso_code": "MA",
199+
"location": {
200+
"lon": -8,
201+
"lat": 31.6
202+
},
203+
"region_name": "Marrakech-Tensift-Al Haouz",
204+
"continent_name": "Africa",
205+
"city_name": "Marrakesh"
206+
},
207+
"event": {
208+
"dataset": "sample_ecommerce"
209+
}
210+
}
211+
}
212+
]
213+
}
214+
}
215+
...
216+
```
217+
218+
Create an index rollup job.
219+
This example picks the `order_date`, `customer_gender`, `geoip.city_name`, `geoip.region_name`, and `day_of_week` fields and rolls them into an `example_rollup` target index:
220+
221+
```json
222+
PUT _opendistro/_rollup/jobs/example
223+
{
224+
"rollup": {
225+
"enabled": true,
226+
"schedule": {
227+
"interval": {
228+
"period": 1,
229+
"unit": "Minutes",
230+
"start_time": 1602100553
231+
}
232+
},
233+
"last_updated_time": 1602100553,
234+
"description": "An example policy that rolls up the sample ecommerce data",
235+
"source_index": "kibana_sample_data_ecommerce",
236+
"target_index": "example_rollup",
237+
"page_size": 1000,
238+
"delay": 0,
239+
"continuous": false,
240+
"dimensions": [
241+
{
242+
"date_histogram": {
243+
"source_field": "order_date",
244+
"fixed_interval": "60m",
245+
"timezone": "America/Los_Angeles"
246+
}
247+
},
248+
{
249+
"terms": {
250+
"source_field": "customer_gender"
251+
}
252+
},
253+
{
254+
"terms": {
255+
"source_field": "geoip.city_name"
256+
}
257+
},
258+
{
259+
"terms": {
260+
"source_field": "geoip.region_name"
261+
}
262+
},
263+
{
264+
"terms": {
265+
"source_field": "day_of_week"
266+
}
267+
}
268+
],
269+
"metrics": [
270+
{
271+
"source_field": "taxless_total_price",
272+
"metrics": [
273+
{
274+
"avg": {}
275+
},
276+
{
277+
"sum": {}
278+
},
279+
{
280+
"max": {}
281+
},
282+
{
283+
"min": {}
284+
},
285+
{
286+
"value_count": {}
287+
}
288+
]
289+
},
290+
{
291+
"source_field": "total_quantity",
292+
"metrics": [
293+
{
294+
"avg": {}
295+
},
296+
{
297+
"max": {}
298+
}
299+
]
300+
}
301+
]
302+
}
303+
}
304+
```
305+
306+
You can query the `example_rollup` index for the terms aggregations on the fields set up in the rollup job.
307+
You get back the same response that you would on the original `kibana_sample_data_ecommerce` source index.
308+
309+
```json
310+
POST example_rollup/_search
311+
{
312+
"size": 0,
313+
"query": {
314+
"bool": {
315+
"must": {"term": { "geoip.region_name": "California" } }
316+
}
317+
},
318+
"aggregations": {
319+
"daily_numbers": {
320+
"terms": {
321+
"field": "day_of_week"
322+
},
323+
"aggs": {
324+
"per_city": {
325+
"terms": {
326+
"field": "geoip.city_name"
327+
},
328+
"aggregations": {
329+
"average quantity": {
330+
"avg": {
331+
"field": "total_quantity"
332+
}
333+
}
334+
}
335+
},
336+
"total_revenue": {
337+
"sum": {
338+
"field": "taxless_total_price"
339+
}
340+
}
341+
}
342+
}
343+
}
344+
}
345+
```
346+
347+
#### Sample Response
348+
349+
```json
350+
{
351+
"took": 476,
352+
"timed_out": false,
353+
"_shards": {
354+
"total": 1,
355+
"successful": 1,
356+
"skipped": 0,
357+
"failed": 0
358+
},
359+
"hits": {
360+
"total": {
361+
"value": 281,
362+
"relation": "eq"
363+
},
364+
"max_score": null,
365+
"hits": []
366+
},
367+
"aggregations": {
368+
"daily_numbers": {
369+
"doc_count_error_upper_bound": 0,
370+
"sum_other_doc_count": 0,
371+
"buckets": [
372+
{
373+
"key": "Friday",
374+
"doc_count": 53,
375+
"total_revenue": {
376+
"value": 4858.84375
377+
},
378+
"per_city": {
379+
"doc_count_error_upper_bound": 0,
380+
"sum_other_doc_count": 0,
381+
"buckets": [
382+
{
383+
"key": "Los Angeles",
384+
"doc_count": 53,
385+
"average quantity": {
386+
"value": 2.305084745762712
387+
}
388+
}
389+
]
390+
}
391+
},
392+
{
393+
"key": "Saturday",
394+
"doc_count": 43,
395+
"total_revenue": {
396+
"value": 3547.203125
397+
},
398+
"per_city": {
399+
"doc_count_error_upper_bound": 0,
400+
"sum_other_doc_count": 0,
401+
"buckets": [
402+
{
403+
"key": "Los Angeles",
404+
"doc_count": 43,
405+
"average quantity": {
406+
"value": 2.260869565217391
407+
}
408+
}
409+
]
410+
}
411+
},
412+
{
413+
"key": "Tuesday",
414+
"doc_count": 42,
415+
"total_revenue": {
416+
"value": 3983.28125
417+
},
418+
"per_city": {
419+
"doc_count_error_upper_bound": 0,
420+
"sum_other_doc_count": 0,
421+
"buckets": [
422+
{
423+
"key": "Los Angeles",
424+
"doc_count": 42,
425+
"average quantity": {
426+
"value": 2.2888888888888888
427+
}
428+
}
429+
]
430+
}
431+
},
432+
{
433+
"key": "Sunday",
434+
"doc_count": 40,
435+
"total_revenue": {
436+
"value": 3308.1640625
437+
},
438+
"per_city": {
439+
"doc_count_error_upper_bound": 0,
440+
"sum_other_doc_count": 0,
441+
"buckets": [
442+
{
443+
"key": "Los Angeles",
444+
"doc_count": 40,
445+
"average quantity": {
446+
"value": 2.090909090909091
447+
}
448+
}
449+
]
450+
}
451+
}
452+
...
453+
]
454+
}
455+
}
456+
}
457+
```

0 commit comments

Comments
 (0)