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