elasticlink 0.2.1-beta → 0.3.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +162 -163
  2. package/dist/aggregation.builder.d.ts +4 -2
  3. package/dist/aggregation.builder.d.ts.map +1 -1
  4. package/dist/aggregation.builder.js +1 -1
  5. package/dist/aggregation.types.d.ts +15 -14
  6. package/dist/aggregation.types.d.ts.map +1 -1
  7. package/dist/bulk.builder.d.ts +115 -1
  8. package/dist/bulk.builder.d.ts.map +1 -1
  9. package/dist/bulk.builder.js +1 -1
  10. package/dist/field.helpers.d.ts +39 -44
  11. package/dist/field.helpers.d.ts.map +1 -1
  12. package/dist/field.helpers.js +15 -19
  13. package/dist/field.types.d.ts +35 -5
  14. package/dist/field.types.d.ts.map +1 -1
  15. package/dist/field.types.js +3 -3
  16. package/dist/index-management.builder.d.ts +5 -12
  17. package/dist/index-management.builder.d.ts.map +1 -1
  18. package/dist/index-management.builder.js +10 -32
  19. package/dist/index-management.types.d.ts +10 -64
  20. package/dist/index-management.types.d.ts.map +1 -1
  21. package/dist/index-management.types.js +0 -1
  22. package/dist/index.d.ts +16 -12
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +10 -8
  25. package/dist/mapping.builder.d.ts +24 -0
  26. package/dist/mapping.builder.d.ts.map +1 -0
  27. package/dist/mapping.builder.js +23 -0
  28. package/dist/mapping.types.d.ts +82 -0
  29. package/dist/mapping.types.d.ts.map +1 -0
  30. package/dist/mapping.types.js +6 -0
  31. package/dist/multi-search.builder.d.ts +5 -3
  32. package/dist/multi-search.builder.d.ts.map +1 -1
  33. package/dist/multi-search.builder.js +2 -2
  34. package/dist/multi-search.types.d.ts +7 -6
  35. package/dist/multi-search.types.d.ts.map +1 -1
  36. package/dist/query.builder.d.ts +3 -7
  37. package/dist/query.builder.d.ts.map +1 -1
  38. package/dist/query.builder.js +30 -92
  39. package/dist/query.types.d.ts +85 -235
  40. package/dist/query.types.d.ts.map +1 -1
  41. package/dist/query.types.js +2 -1
  42. package/dist/suggester.builder.d.ts +5 -3
  43. package/dist/suggester.builder.d.ts.map +1 -1
  44. package/dist/suggester.builder.js +2 -2
  45. package/dist/suggester.types.d.ts +5 -4
  46. package/dist/suggester.types.d.ts.map +1 -1
  47. package/package.json +7 -7
  48. package/dist/__tests__/aggregation-builder.test.d.ts +0 -2
  49. package/dist/__tests__/aggregation-builder.test.d.ts.map +0 -1
  50. package/dist/__tests__/aggregation-builder.test.js +0 -662
  51. package/dist/__tests__/bulk.test.d.ts +0 -2
  52. package/dist/__tests__/bulk.test.d.ts.map +0 -1
  53. package/dist/__tests__/bulk.test.js +0 -684
  54. package/dist/__tests__/examples.test.d.ts +0 -2
  55. package/dist/__tests__/examples.test.d.ts.map +0 -1
  56. package/dist/__tests__/examples.test.js +0 -2006
  57. package/dist/__tests__/fixtures/finance.d.ts +0 -26
  58. package/dist/__tests__/fixtures/finance.d.ts.map +0 -1
  59. package/dist/__tests__/fixtures/finance.js +0 -32
  60. package/dist/__tests__/fixtures/legal.d.ts +0 -8
  61. package/dist/__tests__/fixtures/legal.d.ts.map +0 -1
  62. package/dist/__tests__/fixtures/legal.js +0 -20
  63. package/dist/__tests__/fixtures/real-estate.d.ts +0 -19
  64. package/dist/__tests__/fixtures/real-estate.d.ts.map +0 -1
  65. package/dist/__tests__/fixtures/real-estate.js +0 -20
  66. package/dist/__tests__/index-management.test.d.ts +0 -2
  67. package/dist/__tests__/index-management.test.d.ts.map +0 -1
  68. package/dist/__tests__/index-management.test.js +0 -1148
  69. package/dist/__tests__/integration/aggregation.integration.test.d.ts +0 -2
  70. package/dist/__tests__/integration/aggregation.integration.test.d.ts.map +0 -1
  71. package/dist/__tests__/integration/aggregation.integration.test.js +0 -200
  72. package/dist/__tests__/integration/bulk.integration.test.d.ts +0 -2
  73. package/dist/__tests__/integration/bulk.integration.test.d.ts.map +0 -1
  74. package/dist/__tests__/integration/bulk.integration.test.js +0 -93
  75. package/dist/__tests__/integration/fixtures/finance.d.ts +0 -17
  76. package/dist/__tests__/integration/fixtures/finance.d.ts.map +0 -1
  77. package/dist/__tests__/integration/fixtures/finance.js +0 -42
  78. package/dist/__tests__/integration/fixtures/legal.d.ts +0 -21
  79. package/dist/__tests__/integration/fixtures/legal.d.ts.map +0 -1
  80. package/dist/__tests__/integration/fixtures/legal.js +0 -52
  81. package/dist/__tests__/integration/fixtures/real-estate.d.ts +0 -7
  82. package/dist/__tests__/integration/fixtures/real-estate.d.ts.map +0 -1
  83. package/dist/__tests__/integration/fixtures/real-estate.js +0 -22
  84. package/dist/__tests__/integration/helpers.d.ts +0 -15
  85. package/dist/__tests__/integration/helpers.d.ts.map +0 -1
  86. package/dist/__tests__/integration/helpers.js +0 -21
  87. package/dist/__tests__/integration/index-management.integration.test.d.ts +0 -2
  88. package/dist/__tests__/integration/index-management.integration.test.d.ts.map +0 -1
  89. package/dist/__tests__/integration/index-management.integration.test.js +0 -79
  90. package/dist/__tests__/integration/multi-search.integration.test.d.ts +0 -2
  91. package/dist/__tests__/integration/multi-search.integration.test.d.ts.map +0 -1
  92. package/dist/__tests__/integration/multi-search.integration.test.js +0 -55
  93. package/dist/__tests__/integration/query.integration.test.d.ts +0 -2
  94. package/dist/__tests__/integration/query.integration.test.d.ts.map +0 -1
  95. package/dist/__tests__/integration/query.integration.test.js +0 -118
  96. package/dist/__tests__/integration/suggester.integration.test.d.ts +0 -2
  97. package/dist/__tests__/integration/suggester.integration.test.d.ts.map +0 -1
  98. package/dist/__tests__/integration/suggester.integration.test.js +0 -48
  99. package/dist/__tests__/multi-search.test.d.ts +0 -2
  100. package/dist/__tests__/multi-search.test.d.ts.map +0 -1
  101. package/dist/__tests__/multi-search.test.js +0 -336
  102. package/dist/__tests__/query-builder.test.d.ts +0 -2
  103. package/dist/__tests__/query-builder.test.d.ts.map +0 -1
  104. package/dist/__tests__/query-builder.test.js +0 -5624
  105. package/dist/__tests__/suggester.test.d.ts +0 -2
  106. package/dist/__tests__/suggester.test.d.ts.map +0 -1
  107. package/dist/__tests__/suggester.test.js +0 -1001
@@ -1,662 +0,0 @@
1
- import { aggregations } from '..';
2
- describe('AggregationBuilder', () => {
3
- describe('Builder behavior', () => {
4
- it('should return empty object for empty builder', () => {
5
- const result = aggregations().build();
6
- expect(result).toMatchInlineSnapshot(`{}`);
7
- });
8
- it('should throw when calling subAgg without parent aggregation', () => {
9
- expect(() => {
10
- aggregations()
11
- .subAgg((agg) => agg.avg('avg_price', 'list_price'))
12
- .build();
13
- }).toThrow('No aggregation to add sub-aggregation to');
14
- });
15
- it('should support multiple top-level aggregations at same level', () => {
16
- const result = aggregations()
17
- .terms('by_property_class', 'property_class')
18
- .avg('avg_price', 'list_price')
19
- .dateHistogram('over_time', 'listed_date', { interval: 'month' })
20
- .build();
21
- expect(result).toMatchInlineSnapshot(`
22
- {
23
- "avg_price": {
24
- "avg": {
25
- "field": "list_price",
26
- },
27
- },
28
- "by_property_class": {
29
- "terms": {
30
- "field": "property_class",
31
- },
32
- },
33
- "over_time": {
34
- "date_histogram": {
35
- "field": "listed_date",
36
- "interval": "month",
37
- },
38
- },
39
- }
40
- `);
41
- });
42
- });
43
- describe('Bucket aggregations', () => {
44
- it('should create a terms aggregation', () => {
45
- const result = aggregations()
46
- .terms('category_agg', 'property_class', { size: 10 })
47
- .build();
48
- expect(result).toMatchInlineSnapshot(`
49
- {
50
- "category_agg": {
51
- "terms": {
52
- "field": "property_class",
53
- "size": 10,
54
- },
55
- },
56
- }
57
- `);
58
- });
59
- it('should create a terms aggregation without options', () => {
60
- const result = aggregations()
61
- .terms('category_agg', 'property_class')
62
- .build();
63
- expect(result).toMatchInlineSnapshot(`
64
- {
65
- "category_agg": {
66
- "terms": {
67
- "field": "property_class",
68
- },
69
- },
70
- }
71
- `);
72
- });
73
- it('should create a date histogram aggregation', () => {
74
- const result = aggregations()
75
- .dateHistogram('listings_by_date', 'listed_date', {
76
- interval: 'day',
77
- min_doc_count: 1
78
- })
79
- .build();
80
- expect(result).toMatchInlineSnapshot(`
81
- {
82
- "listings_by_date": {
83
- "date_histogram": {
84
- "field": "listed_date",
85
- "interval": "day",
86
- "min_doc_count": 1,
87
- },
88
- },
89
- }
90
- `);
91
- });
92
- it('should create a range aggregation', () => {
93
- const result = aggregations()
94
- .range('price_ranges', 'list_price', {
95
- ranges: [{ to: 100 }, { from: 100, to: 500 }, { from: 500 }]
96
- })
97
- .build();
98
- expect(result).toMatchInlineSnapshot(`
99
- {
100
- "price_ranges": {
101
- "range": {
102
- "field": "list_price",
103
- "ranges": [
104
- {
105
- "to": 100,
106
- },
107
- {
108
- "from": 100,
109
- "to": 500,
110
- },
111
- {
112
- "from": 500,
113
- },
114
- ],
115
- },
116
- },
117
- }
118
- `);
119
- });
120
- it('should create a histogram aggregation', () => {
121
- const result = aggregations()
122
- .histogram('price_histogram', 'list_price', { interval: 50 })
123
- .build();
124
- expect(result).toMatchInlineSnapshot(`
125
- {
126
- "price_histogram": {
127
- "histogram": {
128
- "field": "list_price",
129
- "interval": 50,
130
- },
131
- },
132
- }
133
- `);
134
- });
135
- });
136
- describe('Metric aggregations', () => {
137
- it('should create an avg aggregation', () => {
138
- const result = aggregations()
139
- .avg('avg_price', 'list_price')
140
- .build();
141
- expect(result).toMatchInlineSnapshot(`
142
- {
143
- "avg_price": {
144
- "avg": {
145
- "field": "list_price",
146
- },
147
- },
148
- }
149
- `);
150
- });
151
- it('should create a sum aggregation', () => {
152
- const result = aggregations()
153
- .sum('total_price', 'list_price')
154
- .build();
155
- expect(result).toMatchInlineSnapshot(`
156
- {
157
- "total_price": {
158
- "sum": {
159
- "field": "list_price",
160
- },
161
- },
162
- }
163
- `);
164
- });
165
- it('should create a min aggregation', () => {
166
- const result = aggregations()
167
- .min('min_price', 'list_price')
168
- .build();
169
- expect(result).toMatchInlineSnapshot(`
170
- {
171
- "min_price": {
172
- "min": {
173
- "field": "list_price",
174
- },
175
- },
176
- }
177
- `);
178
- });
179
- it('should create a max aggregation', () => {
180
- const result = aggregations()
181
- .max('max_price', 'list_price')
182
- .build();
183
- expect(result).toMatchInlineSnapshot(`
184
- {
185
- "max_price": {
186
- "max": {
187
- "field": "list_price",
188
- },
189
- },
190
- }
191
- `);
192
- });
193
- it('should create a cardinality aggregation', () => {
194
- const result = aggregations()
195
- .cardinality('unique_categories', 'property_class', {
196
- precision_threshold: 100
197
- })
198
- .build();
199
- expect(result).toMatchInlineSnapshot(`
200
- {
201
- "unique_categories": {
202
- "cardinality": {
203
- "field": "property_class",
204
- "precision_threshold": 100,
205
- },
206
- },
207
- }
208
- `);
209
- });
210
- it('should create a percentiles aggregation', () => {
211
- const result = aggregations()
212
- .percentiles('price_percentiles', 'list_price', {
213
- percents: [25, 50, 75, 95]
214
- })
215
- .build();
216
- expect(result).toMatchInlineSnapshot(`
217
- {
218
- "price_percentiles": {
219
- "percentiles": {
220
- "field": "list_price",
221
- "percents": [
222
- 25,
223
- 50,
224
- 75,
225
- 95,
226
- ],
227
- },
228
- },
229
- }
230
- `);
231
- });
232
- it('should create a percentiles aggregation with no options', () => {
233
- const result = aggregations()
234
- .percentiles('price_percentiles', 'list_price')
235
- .build();
236
- expect(result).toMatchInlineSnapshot(`
237
- {
238
- "price_percentiles": {
239
- "percentiles": {
240
- "field": "list_price",
241
- },
242
- },
243
- }
244
- `);
245
- });
246
- it('should create a stats aggregation', () => {
247
- const result = aggregations()
248
- .stats('price_stats', 'list_price')
249
- .build();
250
- expect(result).toMatchInlineSnapshot(`
251
- {
252
- "price_stats": {
253
- "stats": {
254
- "field": "list_price",
255
- },
256
- },
257
- }
258
- `);
259
- });
260
- it('should create a value_count aggregation', () => {
261
- const result = aggregations()
262
- .valueCount('rating_count', 'cap_rate')
263
- .build();
264
- expect(result).toMatchInlineSnapshot(`
265
- {
266
- "rating_count": {
267
- "value_count": {
268
- "field": "cap_rate",
269
- },
270
- },
271
- }
272
- `);
273
- });
274
- });
275
- describe('Sub-aggregations', () => {
276
- it('should add sub-aggregations to a bucket aggregation', () => {
277
- const result = aggregations()
278
- .terms('categories', 'property_class', { size: 10 })
279
- .subAgg((agg) => agg.avg('avg_price', 'list_price'))
280
- .build();
281
- expect(result).toMatchInlineSnapshot(`
282
- {
283
- "categories": {
284
- "aggs": {
285
- "avg_price": {
286
- "avg": {
287
- "field": "list_price",
288
- },
289
- },
290
- },
291
- "terms": {
292
- "field": "property_class",
293
- "size": 10,
294
- },
295
- },
296
- }
297
- `);
298
- });
299
- it('should add multiple sub-aggregations', () => {
300
- const result = aggregations()
301
- .terms('categories', 'property_class')
302
- .subAgg((agg) => agg.avg('avg_price', 'list_price').max('max_rating', 'cap_rate'))
303
- .build();
304
- expect(result).toMatchInlineSnapshot(`
305
- {
306
- "categories": {
307
- "aggs": {
308
- "avg_price": {
309
- "avg": {
310
- "field": "list_price",
311
- },
312
- },
313
- "max_rating": {
314
- "max": {
315
- "field": "cap_rate",
316
- },
317
- },
318
- },
319
- "terms": {
320
- "field": "property_class",
321
- },
322
- },
323
- }
324
- `);
325
- });
326
- });
327
- describe('Aggregation options', () => {
328
- describe('Terms aggregation options', () => {
329
- it('should create terms with min_doc_count', () => {
330
- const result = aggregations()
331
- .terms('categories', 'property_class', { min_doc_count: 5 })
332
- .build();
333
- expect(result).toMatchInlineSnapshot(`
334
- {
335
- "categories": {
336
- "terms": {
337
- "field": "property_class",
338
- "min_doc_count": 5,
339
- },
340
- },
341
- }
342
- `);
343
- });
344
- it('should create terms with order', () => {
345
- const result = aggregations()
346
- .terms('categories', 'property_class', { order: { _count: 'asc' } })
347
- .build();
348
- expect(result).toMatchInlineSnapshot(`
349
- {
350
- "categories": {
351
- "terms": {
352
- "field": "property_class",
353
- "order": {
354
- "_count": "asc",
355
- },
356
- },
357
- },
358
- }
359
- `);
360
- });
361
- it('should create terms with missing value', () => {
362
- const result = aggregations()
363
- .terms('categories', 'property_class', { missing: 'N/A' })
364
- .build();
365
- expect(result).toMatchInlineSnapshot(`
366
- {
367
- "categories": {
368
- "terms": {
369
- "field": "property_class",
370
- "missing": "N/A",
371
- },
372
- },
373
- }
374
- `);
375
- });
376
- it('should create terms with all options', () => {
377
- const result = aggregations()
378
- .terms('categories', 'property_class', {
379
- size: 20,
380
- min_doc_count: 2,
381
- order: { _key: 'desc' },
382
- missing: 'Unknown'
383
- })
384
- .build();
385
- expect(result.categories.terms).toEqual({
386
- field: 'property_class',
387
- size: 20,
388
- min_doc_count: 2,
389
- order: { _key: 'desc' },
390
- missing: 'Unknown'
391
- });
392
- });
393
- });
394
- describe('Range aggregation options', () => {
395
- it('should create range with keyed ranges', () => {
396
- const result = aggregations()
397
- .range('price_ranges', 'list_price', {
398
- ranges: [
399
- { key: 'cheap', to: 100 },
400
- { key: 'moderate', from: 100, to: 500 },
401
- { key: 'expensive', from: 500 }
402
- ]
403
- })
404
- .build();
405
- expect(result.price_ranges.range.ranges).toMatchInlineSnapshot(`
406
- [
407
- {
408
- "key": "cheap",
409
- "to": 100,
410
- },
411
- {
412
- "from": 100,
413
- "key": "moderate",
414
- "to": 500,
415
- },
416
- {
417
- "from": 500,
418
- "key": "expensive",
419
- },
420
- ]
421
- `);
422
- });
423
- });
424
- describe('DateHistogram aggregation options', () => {
425
- it('should create dateHistogram with minimal options', () => {
426
- const result = aggregations()
427
- .dateHistogram('by_day', 'listed_date', { interval: 'day' })
428
- .build();
429
- expect(result).toMatchInlineSnapshot(`
430
- {
431
- "by_day": {
432
- "date_histogram": {
433
- "field": "listed_date",
434
- "interval": "day",
435
- },
436
- },
437
- }
438
- `);
439
- });
440
- it('should create dateHistogram with extended_bounds', () => {
441
- const result = aggregations()
442
- .dateHistogram('over_time', 'listed_date', {
443
- interval: 'day',
444
- extended_bounds: {
445
- min: '2024-01-01',
446
- max: '2024-12-31'
447
- }
448
- })
449
- .build();
450
- expect(result.over_time.date_histogram.extended_bounds).toEqual({
451
- min: '2024-01-01',
452
- max: '2024-12-31'
453
- });
454
- });
455
- it('should create dateHistogram with time_zone', () => {
456
- const result = aggregations()
457
- .dateHistogram('over_time', 'listed_date', {
458
- interval: 'day',
459
- time_zone: 'America/New_York'
460
- })
461
- .build();
462
- expect(result.over_time.date_histogram.time_zone).toBe('America/New_York');
463
- });
464
- it('should create dateHistogram with order', () => {
465
- const result = aggregations()
466
- .dateHistogram('over_time', 'listed_date', {
467
- interval: 'month',
468
- order: { _key: 'desc' }
469
- })
470
- .build();
471
- expect(result.over_time.date_histogram.order).toEqual({
472
- _key: 'desc'
473
- });
474
- });
475
- });
476
- describe('Histogram aggregation options', () => {
477
- it('should create histogram with min_doc_count', () => {
478
- const result = aggregations()
479
- .histogram('price_buckets', 'list_price', {
480
- interval: 100,
481
- min_doc_count: 1
482
- })
483
- .build();
484
- expect(result.price_buckets.histogram.min_doc_count).toBe(1);
485
- });
486
- it('should create histogram with extended_bounds', () => {
487
- const result = aggregations()
488
- .histogram('price_buckets', 'list_price', {
489
- interval: 50,
490
- extended_bounds: { min: 0, max: 1000 }
491
- })
492
- .build();
493
- expect(result.price_buckets.histogram.extended_bounds).toEqual({
494
- min: 0,
495
- max: 1000
496
- });
497
- });
498
- });
499
- describe('Metric aggregation options', () => {
500
- it('should create avg with missing value', () => {
501
- const result = aggregations()
502
- .avg('avg_price', 'list_price', { missing: 0 })
503
- .build();
504
- expect(result).toMatchInlineSnapshot(`
505
- {
506
- "avg_price": {
507
- "avg": {
508
- "field": "list_price",
509
- "missing": 0,
510
- },
511
- },
512
- }
513
- `);
514
- });
515
- it('should create sum with missing value', () => {
516
- const result = aggregations()
517
- .sum('total_price', 'list_price', { missing: 0 })
518
- .build();
519
- expect(result.total_price.sum.missing).toBe(0);
520
- });
521
- it('should create min with missing value', () => {
522
- const result = aggregations()
523
- .min('min_price', 'list_price', { missing: 9999 })
524
- .build();
525
- expect(result.min_price.min.missing).toBe(9999);
526
- });
527
- it('should create max with missing value', () => {
528
- const result = aggregations()
529
- .max('max_price', 'list_price', { missing: 0 })
530
- .build();
531
- expect(result.max_price.max.missing).toBe(0);
532
- });
533
- it('should create cardinality without options', () => {
534
- const result = aggregations()
535
- .cardinality('unique_categories', 'property_class')
536
- .build();
537
- expect(result).toMatchInlineSnapshot(`
538
- {
539
- "unique_categories": {
540
- "cardinality": {
541
- "field": "property_class",
542
- },
543
- },
544
- }
545
- `);
546
- });
547
- it('should create percentiles with keyed option', () => {
548
- const result = aggregations()
549
- .percentiles('price_percentiles', 'list_price', {
550
- percents: [25, 50, 75, 95, 99],
551
- keyed: true
552
- })
553
- .build();
554
- expect(result.price_percentiles.percentiles.keyed).toBe(true);
555
- expect(result.price_percentiles.percentiles.percents).toEqual([
556
- 25, 50, 75, 95, 99
557
- ]);
558
- });
559
- it('should create stats with missing value', () => {
560
- const result = aggregations()
561
- .stats('price_stats', 'list_price', { missing: 0 })
562
- .build();
563
- expect(result.price_stats.stats.missing).toBe(0);
564
- });
565
- it('should create valueCount with missing value', () => {
566
- const result = aggregations()
567
- .valueCount('rating_count', 'cap_rate', { missing: 0 })
568
- .build();
569
- expect(result.rating_count.value_count.missing).toBe(0);
570
- });
571
- });
572
- describe('Sub-aggregation patterns', () => {
573
- it('should add sub-agg to dateHistogram', () => {
574
- const result = aggregations()
575
- .dateHistogram('by_month', 'listed_date', { interval: 'month' })
576
- .subAgg((sub) => sub
577
- .sum('monthly_revenue', 'list_price')
578
- .avg('avg_rating', 'cap_rate'))
579
- .build();
580
- expect(result).toMatchObject({
581
- by_month: {
582
- date_histogram: { field: 'listed_date', interval: 'month' },
583
- aggs: {
584
- monthly_revenue: { sum: { field: 'list_price' } },
585
- avg_rating: { avg: { field: 'cap_rate' } }
586
- }
587
- }
588
- });
589
- });
590
- it('should add sub-agg to range aggregation', () => {
591
- const result = aggregations()
592
- .range('price_ranges', 'list_price', {
593
- ranges: [{ to: 50 }, { from: 50, to: 100 }, { from: 100 }]
594
- })
595
- .subAgg((sub) => sub.avg('avg_rating', 'cap_rate'))
596
- .build();
597
- expect(result).toMatchObject({
598
- price_ranges: {
599
- range: {
600
- field: 'list_price',
601
- ranges: [{ to: 50 }, { from: 50, to: 100 }, { from: 100 }]
602
- },
603
- aggs: {
604
- avg_rating: { avg: { field: 'cap_rate' } }
605
- }
606
- }
607
- });
608
- });
609
- it('should add sub-agg to histogram aggregation', () => {
610
- const result = aggregations()
611
- .histogram('price_histogram', 'list_price', { interval: 25 })
612
- .subAgg((sub) => sub.cardinality('unique_categories', 'property_class'))
613
- .build();
614
- expect(result).toMatchObject({
615
- price_histogram: {
616
- histogram: { field: 'list_price', interval: 25 },
617
- aggs: {
618
- unique_categories: { cardinality: { field: 'property_class' } }
619
- }
620
- }
621
- });
622
- });
623
- it('should create multiple sibling sub-aggregations', () => {
624
- const result = aggregations()
625
- .terms('by_property_class', 'property_class')
626
- .subAgg((sub) => sub
627
- .avg('avg_price', 'list_price')
628
- .min('min_price', 'list_price')
629
- .max('max_price', 'list_price')
630
- .sum('total_revenue', 'list_price')
631
- .stats('price_stats', 'list_price'))
632
- .build();
633
- expect(result).toMatchObject({
634
- by_property_class: {
635
- terms: { field: 'property_class' },
636
- aggs: {
637
- avg_price: { avg: { field: 'list_price' } },
638
- min_price: { min: { field: 'list_price' } },
639
- max_price: { max: { field: 'list_price' } },
640
- total_revenue: { sum: { field: 'list_price' } },
641
- price_stats: { stats: { field: 'list_price' } }
642
- }
643
- }
644
- });
645
- });
646
- it('should create multiple bucket aggregations at same level', () => {
647
- const result = aggregations()
648
- .terms('by_property_class', 'property_class', { size: 10 })
649
- .terms('by_title', 'title', { size: 5 })
650
- .dateHistogram('by_date', 'listed_date', { interval: 'week' })
651
- .build();
652
- expect(result).toMatchObject({
653
- by_property_class: { terms: { field: 'property_class', size: 10 } },
654
- by_title: { terms: { field: 'title', size: 5 } },
655
- by_date: {
656
- date_histogram: { field: 'listed_date', interval: 'week' }
657
- }
658
- });
659
- });
660
- });
661
- });
662
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=bulk.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bulk.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/bulk.test.ts"],"names":[],"mappings":""}