elasticlink 0.4.0-beta → 0.5.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 (86) hide show
  1. package/README.md +98 -23
  2. package/dist/bulk.builder.d.ts +3 -123
  3. package/dist/bulk.builder.d.ts.map +1 -1
  4. package/dist/field.helpers.d.ts +45 -3
  5. package/dist/field.helpers.d.ts.map +1 -1
  6. package/dist/field.helpers.js +50 -9
  7. package/dist/field.types.d.ts +18 -1
  8. package/dist/field.types.d.ts.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/mapping.builder.d.ts +15 -6
  12. package/dist/mapping.builder.d.ts.map +1 -1
  13. package/dist/mapping.builder.js +1 -0
  14. package/dist/mapping.types.d.ts +44 -12
  15. package/dist/mapping.types.d.ts.map +1 -1
  16. package/dist/query.builder.d.ts.map +1 -1
  17. package/dist/query.builder.js +64 -64
  18. package/dist/query.types.d.ts +57 -5
  19. package/dist/query.types.d.ts.map +1 -1
  20. package/package.json +2 -3
  21. package/dist/__tests__/aggregation-builder.test.d.ts +0 -2
  22. package/dist/__tests__/aggregation-builder.test.d.ts.map +0 -1
  23. package/dist/__tests__/aggregation-builder.test.js +0 -622
  24. package/dist/__tests__/bulk.test.d.ts +0 -2
  25. package/dist/__tests__/bulk.test.d.ts.map +0 -1
  26. package/dist/__tests__/bulk.test.js +0 -679
  27. package/dist/__tests__/examples.test.d.ts +0 -2
  28. package/dist/__tests__/examples.test.d.ts.map +0 -1
  29. package/dist/__tests__/examples.test.js +0 -2123
  30. package/dist/__tests__/fixtures/finance.d.ts +0 -58
  31. package/dist/__tests__/fixtures/finance.d.ts.map +0 -1
  32. package/dist/__tests__/fixtures/finance.js +0 -73
  33. package/dist/__tests__/fixtures/legal.d.ts +0 -14
  34. package/dist/__tests__/fixtures/legal.d.ts.map +0 -1
  35. package/dist/__tests__/fixtures/legal.js +0 -27
  36. package/dist/__tests__/fixtures/real-estate.d.ts +0 -31
  37. package/dist/__tests__/fixtures/real-estate.d.ts.map +0 -1
  38. package/dist/__tests__/fixtures/real-estate.js +0 -39
  39. package/dist/__tests__/index-management.test.d.ts +0 -2
  40. package/dist/__tests__/index-management.test.d.ts.map +0 -1
  41. package/dist/__tests__/index-management.test.js +0 -1699
  42. package/dist/__tests__/integration/aggregation.integration.test.d.ts +0 -2
  43. package/dist/__tests__/integration/aggregation.integration.test.d.ts.map +0 -1
  44. package/dist/__tests__/integration/aggregation.integration.test.js +0 -188
  45. package/dist/__tests__/integration/bulk.integration.test.d.ts +0 -2
  46. package/dist/__tests__/integration/bulk.integration.test.d.ts.map +0 -1
  47. package/dist/__tests__/integration/bulk.integration.test.js +0 -90
  48. package/dist/__tests__/integration/fixtures/finance.d.ts +0 -37
  49. package/dist/__tests__/integration/fixtures/finance.d.ts.map +0 -1
  50. package/dist/__tests__/integration/fixtures/finance.js +0 -58
  51. package/dist/__tests__/integration/fixtures/legal.d.ts +0 -38
  52. package/dist/__tests__/integration/fixtures/legal.d.ts.map +0 -1
  53. package/dist/__tests__/integration/fixtures/legal.js +0 -65
  54. package/dist/__tests__/integration/fixtures/real-estate.d.ts +0 -17
  55. package/dist/__tests__/integration/fixtures/real-estate.d.ts.map +0 -1
  56. package/dist/__tests__/integration/fixtures/real-estate.js +0 -28
  57. package/dist/__tests__/integration/helpers.d.ts +0 -15
  58. package/dist/__tests__/integration/helpers.d.ts.map +0 -1
  59. package/dist/__tests__/integration/helpers.js +0 -21
  60. package/dist/__tests__/integration/index-management.integration.test.d.ts +0 -2
  61. package/dist/__tests__/integration/index-management.integration.test.d.ts.map +0 -1
  62. package/dist/__tests__/integration/index-management.integration.test.js +0 -67
  63. package/dist/__tests__/integration/multi-search.integration.test.d.ts +0 -2
  64. package/dist/__tests__/integration/multi-search.integration.test.d.ts.map +0 -1
  65. package/dist/__tests__/integration/multi-search.integration.test.js +0 -49
  66. package/dist/__tests__/integration/query.integration.test.d.ts +0 -2
  67. package/dist/__tests__/integration/query.integration.test.d.ts.map +0 -1
  68. package/dist/__tests__/integration/query.integration.test.js +0 -101
  69. package/dist/__tests__/integration/suggester.integration.test.d.ts +0 -2
  70. package/dist/__tests__/integration/suggester.integration.test.d.ts.map +0 -1
  71. package/dist/__tests__/integration/suggester.integration.test.js +0 -42
  72. package/dist/__tests__/multi-search.test.d.ts +0 -2
  73. package/dist/__tests__/multi-search.test.d.ts.map +0 -1
  74. package/dist/__tests__/multi-search.test.js +0 -325
  75. package/dist/__tests__/query-builder-extensions.test.d.ts +0 -2
  76. package/dist/__tests__/query-builder-extensions.test.d.ts.map +0 -1
  77. package/dist/__tests__/query-builder-extensions.test.js +0 -436
  78. package/dist/__tests__/query-builder.test.d.ts +0 -2
  79. package/dist/__tests__/query-builder.test.d.ts.map +0 -1
  80. package/dist/__tests__/query-builder.test.js +0 -5482
  81. package/dist/__tests__/settings-presets.test.d.ts +0 -2
  82. package/dist/__tests__/settings-presets.test.d.ts.map +0 -1
  83. package/dist/__tests__/settings-presets.test.js +0 -183
  84. package/dist/__tests__/suggester.test.d.ts +0 -2
  85. package/dist/__tests__/suggester.test.d.ts.map +0 -1
  86. package/dist/__tests__/suggester.test.js +0 -1006
@@ -1,436 +0,0 @@
1
- import { query } from '..';
2
- import { instrumentMappings, scoredInstrumentMappings } from './fixtures/finance';
3
- describe('QueryBuilder Extensions', () => {
4
- describe('Search parameters', () => {
5
- it('should build searchAfter', () => {
6
- const result = query(instrumentMappings)
7
- .sort('listed_date', 'desc')
8
- .size(10)
9
- .searchAfter(['2004-08-19', 'US38259P5089'])
10
- .build();
11
- expect(result).toMatchInlineSnapshot(`
12
- {
13
- "search_after": [
14
- "2004-08-19",
15
- "US38259P5089",
16
- ],
17
- "size": 10,
18
- "sort": [
19
- {
20
- "listed_date": "desc",
21
- },
22
- ],
23
- }
24
- `);
25
- });
26
- it('should build preference', () => {
27
- const result = query(instrumentMappings).matchAll().preference('session-abc-123').build();
28
- expect(result).toMatchInlineSnapshot(`
29
- {
30
- "preference": "session-abc-123",
31
- "query": {
32
- "match_all": {},
33
- },
34
- }
35
- `);
36
- });
37
- it('should build collapse with field only', () => {
38
- const result = query(instrumentMappings).matchAll().collapse('sector').build();
39
- expect(result).toMatchInlineSnapshot(`
40
- {
41
- "collapse": {
42
- "field": "sector",
43
- },
44
- "query": {
45
- "match_all": {},
46
- },
47
- }
48
- `);
49
- });
50
- it('should build collapse with options', () => {
51
- const result = query(instrumentMappings)
52
- .matchAll()
53
- .collapse('sector', {
54
- inner_hits: { name: 'by_sector', size: 3 },
55
- max_concurrent_group_searches: 4
56
- })
57
- .build();
58
- expect(result).toMatchInlineSnapshot(`
59
- {
60
- "collapse": {
61
- "field": "sector",
62
- "inner_hits": {
63
- "name": "by_sector",
64
- "size": 3,
65
- },
66
- "max_concurrent_group_searches": 4,
67
- },
68
- "query": {
69
- "match_all": {},
70
- },
71
- }
72
- `);
73
- });
74
- it('should build rescore', () => {
75
- const result = query(instrumentMappings)
76
- .match('name', 'Apple')
77
- .rescore((q) => q.matchPhrase('name', 'Apple Inc'), 100, {
78
- rescore_query_weight: 2,
79
- score_mode: 'multiply'
80
- })
81
- .build();
82
- expect(result).toMatchInlineSnapshot(`
83
- {
84
- "query": {
85
- "match": {
86
- "name": "Apple",
87
- },
88
- },
89
- "rescore": {
90
- "query": {
91
- "rescore_query": {
92
- "match_phrase": {
93
- "name": "Apple Inc",
94
- },
95
- },
96
- "rescore_query_weight": 2,
97
- "score_mode": "multiply",
98
- },
99
- "window_size": 100,
100
- },
101
- }
102
- `);
103
- });
104
- it('should build rescore with minimal options', () => {
105
- const result = query(instrumentMappings)
106
- .matchAll()
107
- .rescore((q) => q.match('name', 'tech'), 50)
108
- .build();
109
- expect(result).toMatchInlineSnapshot(`
110
- {
111
- "query": {
112
- "match_all": {},
113
- },
114
- "rescore": {
115
- "query": {
116
- "rescore_query": {
117
- "match": {
118
- "name": "tech",
119
- },
120
- },
121
- },
122
- "window_size": 50,
123
- },
124
- }
125
- `);
126
- });
127
- it('should build storedFields', () => {
128
- const result = query(instrumentMappings).matchAll().storedFields(['_none_']).build();
129
- expect(result).toMatchInlineSnapshot(`
130
- {
131
- "query": {
132
- "match_all": {},
133
- },
134
- "stored_fields": [
135
- "_none_",
136
- ],
137
- }
138
- `);
139
- });
140
- it('should build terminateAfter', () => {
141
- const result = query(instrumentMappings).term('asset_class', 'equity').terminateAfter(1).build();
142
- expect(result).toMatchInlineSnapshot(`
143
- {
144
- "query": {
145
- "term": {
146
- "asset_class": "equity",
147
- },
148
- },
149
- "terminate_after": 1,
150
- }
151
- `);
152
- });
153
- it('should build indicesBoost', () => {
154
- const result = query(instrumentMappings)
155
- .matchAll()
156
- .indicesBoost([{ 'instruments-2024': 1.5 }, { 'instruments-2023': 1.0 }])
157
- .build();
158
- expect(result).toMatchInlineSnapshot(`
159
- {
160
- "indices_boost": [
161
- {
162
- "instruments-2024": 1.5,
163
- },
164
- {
165
- "instruments-2023": 1,
166
- },
167
- ],
168
- "query": {
169
- "match_all": {},
170
- },
171
- }
172
- `);
173
- });
174
- it('should chain multiple search parameters', () => {
175
- const result = query(instrumentMappings)
176
- .match('name', 'Apple')
177
- .sort('listed_date', 'desc')
178
- .size(10)
179
- .searchAfter(['2004-08-19'])
180
- .preference('session-123')
181
- .trackTotalHits(false)
182
- .terminateAfter(100)
183
- .build();
184
- expect(result).toMatchInlineSnapshot(`
185
- {
186
- "preference": "session-123",
187
- "query": {
188
- "match": {
189
- "name": "Apple",
190
- },
191
- },
192
- "search_after": [
193
- "2004-08-19",
194
- ],
195
- "size": 10,
196
- "sort": [
197
- {
198
- "listed_date": "desc",
199
- },
200
- ],
201
- "terminate_after": 100,
202
- "track_total_hits": false,
203
- }
204
- `);
205
- });
206
- });
207
- describe('New query types', () => {
208
- it('should build combinedFields query', () => {
209
- const result = query(scoredInstrumentMappings).combinedFields(['name', 'address'], 'technology company').build();
210
- expect(result).toMatchInlineSnapshot(`
211
- {
212
- "query": {
213
- "combined_fields": {
214
- "fields": [
215
- "name",
216
- "address",
217
- ],
218
- "query": "technology company",
219
- },
220
- },
221
- }
222
- `);
223
- });
224
- it('should build combinedFields query with options', () => {
225
- const result = query(scoredInstrumentMappings)
226
- .combinedFields(['name', 'address'], 'tech', { operator: 'and' })
227
- .build();
228
- expect(result).toMatchInlineSnapshot(`
229
- {
230
- "query": {
231
- "combined_fields": {
232
- "fields": [
233
- "name",
234
- "address",
235
- ],
236
- "operator": "and",
237
- "query": "tech",
238
- },
239
- },
240
- }
241
- `);
242
- });
243
- it('should build queryString query', () => {
244
- const result = query(instrumentMappings).queryString('name:Apple AND sector:technology').build();
245
- expect(result).toMatchInlineSnapshot(`
246
- {
247
- "query": {
248
- "query_string": {
249
- "query": "name:Apple AND sector:technology",
250
- },
251
- },
252
- }
253
- `);
254
- });
255
- it('should build queryString query with options', () => {
256
- const result = query(instrumentMappings).queryString('Apple OR Google', { default_field: 'name' }).build();
257
- expect(result).toMatchInlineSnapshot(`
258
- {
259
- "query": {
260
- "query_string": {
261
- "default_field": "name",
262
- "query": "Apple OR Google",
263
- },
264
- },
265
- }
266
- `);
267
- });
268
- it('should build simpleQueryString query', () => {
269
- const result = query(instrumentMappings).simpleQueryString('"Apple Inc" +technology').build();
270
- expect(result).toMatchInlineSnapshot(`
271
- {
272
- "query": {
273
- "simple_query_string": {
274
- "query": ""Apple Inc" +technology",
275
- },
276
- },
277
- }
278
- `);
279
- });
280
- it('should build simpleQueryString query with options', () => {
281
- const result = query(instrumentMappings)
282
- .simpleQueryString('Apple Google', {
283
- fields: ['name'],
284
- default_operator: 'and'
285
- })
286
- .build();
287
- expect(result).toMatchInlineSnapshot(`
288
- {
289
- "query": {
290
- "simple_query_string": {
291
- "default_operator": "and",
292
- "fields": [
293
- "name",
294
- ],
295
- "query": "Apple Google",
296
- },
297
- },
298
- }
299
- `);
300
- });
301
- it('should build moreLikeThis query with text', () => {
302
- const result = query(instrumentMappings).moreLikeThis(['name'], 'Apple Inc technology company').build();
303
- expect(result).toMatchInlineSnapshot(`
304
- {
305
- "query": {
306
- "more_like_this": {
307
- "fields": [
308
- "name",
309
- ],
310
- "like": [
311
- "Apple Inc technology company",
312
- ],
313
- },
314
- },
315
- }
316
- `);
317
- });
318
- it('should build moreLikeThis query with doc reference', () => {
319
- const result = query(instrumentMappings)
320
- .moreLikeThis(['name'], [{ _index: 'instruments', _id: '1' }], {
321
- min_term_freq: 1,
322
- max_query_terms: 12
323
- })
324
- .build();
325
- expect(result).toMatchInlineSnapshot(`
326
- {
327
- "query": {
328
- "more_like_this": {
329
- "fields": [
330
- "name",
331
- ],
332
- "like": [
333
- {
334
- "_id": "1",
335
- "_index": "instruments",
336
- },
337
- ],
338
- "max_query_terms": 12,
339
- "min_term_freq": 1,
340
- },
341
- },
342
- }
343
- `);
344
- });
345
- it('should build matchBoolPrefix query', () => {
346
- const result = query(instrumentMappings).matchBoolPrefix('name', 'Apple I').build();
347
- expect(result).toMatchInlineSnapshot(`
348
- {
349
- "query": {
350
- "match_bool_prefix": {
351
- "name": "Apple I",
352
- },
353
- },
354
- }
355
- `);
356
- });
357
- it('should build matchBoolPrefix query with options', () => {
358
- const result = query(instrumentMappings).matchBoolPrefix('name', 'Apple I', { analyzer: 'standard' }).build();
359
- expect(result).toMatchInlineSnapshot(`
360
- {
361
- "query": {
362
- "match_bool_prefix": {
363
- "name": {
364
- "analyzer": "standard",
365
- "query": "Apple I",
366
- },
367
- },
368
- },
369
- }
370
- `);
371
- });
372
- it('should use new query types inside bool clauses', () => {
373
- const result = query(instrumentMappings)
374
- .bool()
375
- .must((q) => q.simpleQueryString('Apple'))
376
- .must((q) => q.combinedFields(['name'], 'tech'))
377
- .must((q) => q.queryString('name:Apple'))
378
- .must((q) => q.moreLikeThis(['name'], 'Apple Inc'))
379
- .filter((q) => q.term('asset_class', 'equity'))
380
- .should((q) => q.matchBoolPrefix('name', 'App'))
381
- .build();
382
- expect(result).toMatchInlineSnapshot(`
383
- {
384
- "query": {
385
- "bool": {
386
- "filter": [
387
- {
388
- "term": {
389
- "asset_class": "equity",
390
- },
391
- },
392
- ],
393
- "must": [
394
- {
395
- "simple_query_string": {
396
- "query": "Apple",
397
- },
398
- },
399
- {
400
- "combined_fields": {
401
- "fields": [
402
- "name",
403
- ],
404
- "query": "tech",
405
- },
406
- },
407
- {
408
- "query_string": {
409
- "query": "name:Apple",
410
- },
411
- },
412
- {
413
- "more_like_this": {
414
- "fields": [
415
- "name",
416
- ],
417
- "like": [
418
- "Apple Inc",
419
- ],
420
- },
421
- },
422
- ],
423
- "should": [
424
- {
425
- "match_bool_prefix": {
426
- "name": "App",
427
- },
428
- },
429
- ],
430
- },
431
- },
432
- }
433
- `);
434
- });
435
- });
436
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=query-builder.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-builder.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/query-builder.test.ts"],"names":[],"mappings":""}