elasticlink 0.2.1-beta → 0.2.2-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 (64) hide show
  1. package/dist/query.builder.js +1 -1
  2. package/dist/query.types.d.ts +1 -1
  3. package/dist/query.types.d.ts.map +1 -1
  4. package/package.json +1 -1
  5. package/dist/__tests__/aggregation-builder.test.d.ts +0 -2
  6. package/dist/__tests__/aggregation-builder.test.d.ts.map +0 -1
  7. package/dist/__tests__/aggregation-builder.test.js +0 -662
  8. package/dist/__tests__/bulk.test.d.ts +0 -2
  9. package/dist/__tests__/bulk.test.d.ts.map +0 -1
  10. package/dist/__tests__/bulk.test.js +0 -684
  11. package/dist/__tests__/examples.test.d.ts +0 -2
  12. package/dist/__tests__/examples.test.d.ts.map +0 -1
  13. package/dist/__tests__/examples.test.js +0 -2006
  14. package/dist/__tests__/fixtures/finance.d.ts +0 -26
  15. package/dist/__tests__/fixtures/finance.d.ts.map +0 -1
  16. package/dist/__tests__/fixtures/finance.js +0 -32
  17. package/dist/__tests__/fixtures/legal.d.ts +0 -8
  18. package/dist/__tests__/fixtures/legal.d.ts.map +0 -1
  19. package/dist/__tests__/fixtures/legal.js +0 -20
  20. package/dist/__tests__/fixtures/real-estate.d.ts +0 -19
  21. package/dist/__tests__/fixtures/real-estate.d.ts.map +0 -1
  22. package/dist/__tests__/fixtures/real-estate.js +0 -20
  23. package/dist/__tests__/index-management.test.d.ts +0 -2
  24. package/dist/__tests__/index-management.test.d.ts.map +0 -1
  25. package/dist/__tests__/index-management.test.js +0 -1148
  26. package/dist/__tests__/integration/aggregation.integration.test.d.ts +0 -2
  27. package/dist/__tests__/integration/aggregation.integration.test.d.ts.map +0 -1
  28. package/dist/__tests__/integration/aggregation.integration.test.js +0 -200
  29. package/dist/__tests__/integration/bulk.integration.test.d.ts +0 -2
  30. package/dist/__tests__/integration/bulk.integration.test.d.ts.map +0 -1
  31. package/dist/__tests__/integration/bulk.integration.test.js +0 -93
  32. package/dist/__tests__/integration/fixtures/finance.d.ts +0 -17
  33. package/dist/__tests__/integration/fixtures/finance.d.ts.map +0 -1
  34. package/dist/__tests__/integration/fixtures/finance.js +0 -42
  35. package/dist/__tests__/integration/fixtures/legal.d.ts +0 -21
  36. package/dist/__tests__/integration/fixtures/legal.d.ts.map +0 -1
  37. package/dist/__tests__/integration/fixtures/legal.js +0 -52
  38. package/dist/__tests__/integration/fixtures/real-estate.d.ts +0 -7
  39. package/dist/__tests__/integration/fixtures/real-estate.d.ts.map +0 -1
  40. package/dist/__tests__/integration/fixtures/real-estate.js +0 -22
  41. package/dist/__tests__/integration/helpers.d.ts +0 -15
  42. package/dist/__tests__/integration/helpers.d.ts.map +0 -1
  43. package/dist/__tests__/integration/helpers.js +0 -21
  44. package/dist/__tests__/integration/index-management.integration.test.d.ts +0 -2
  45. package/dist/__tests__/integration/index-management.integration.test.d.ts.map +0 -1
  46. package/dist/__tests__/integration/index-management.integration.test.js +0 -79
  47. package/dist/__tests__/integration/multi-search.integration.test.d.ts +0 -2
  48. package/dist/__tests__/integration/multi-search.integration.test.d.ts.map +0 -1
  49. package/dist/__tests__/integration/multi-search.integration.test.js +0 -55
  50. package/dist/__tests__/integration/query.integration.test.d.ts +0 -2
  51. package/dist/__tests__/integration/query.integration.test.d.ts.map +0 -1
  52. package/dist/__tests__/integration/query.integration.test.js +0 -118
  53. package/dist/__tests__/integration/suggester.integration.test.d.ts +0 -2
  54. package/dist/__tests__/integration/suggester.integration.test.d.ts.map +0 -1
  55. package/dist/__tests__/integration/suggester.integration.test.js +0 -48
  56. package/dist/__tests__/multi-search.test.d.ts +0 -2
  57. package/dist/__tests__/multi-search.test.d.ts.map +0 -1
  58. package/dist/__tests__/multi-search.test.js +0 -336
  59. package/dist/__tests__/query-builder.test.d.ts +0 -2
  60. package/dist/__tests__/query-builder.test.d.ts.map +0 -1
  61. package/dist/__tests__/query-builder.test.js +0 -5624
  62. package/dist/__tests__/suggester.test.d.ts +0 -2
  63. package/dist/__tests__/suggester.test.d.ts.map +0 -1
  64. package/dist/__tests__/suggester.test.js +0 -1001
@@ -1,1148 +0,0 @@
1
- import { indexBuilder, text, keyword, float, integer, date, boolean, denseVector, nested, scaledFloat, geoPoint, dateRange, percolator, completion, halfFloat, geoShape, ip, binary, integerRange, floatRange, longRange, doubleRange, object, alias } from '..';
2
- describe('Index Management', () => {
3
- describe('Builder behavior', () => {
4
- it('should return empty object for empty builder', () => {
5
- const result = indexBuilder().build();
6
- expect(result).toMatchInlineSnapshot(`{}`);
7
- });
8
- it('should replace mappings when called twice', () => {
9
- const result = indexBuilder()
10
- .mappings({ name: 'text' })
11
- .mappings({ market_cap: 'float' })
12
- .build();
13
- expect(result).toMatchInlineSnapshot(`
14
- {
15
- "mappings": {
16
- "properties": {
17
- "market_cap": {
18
- "type": "float",
19
- },
20
- },
21
- },
22
- }
23
- `);
24
- });
25
- it('should replace settings when called twice', () => {
26
- const result = indexBuilder()
27
- .settings({ number_of_shards: 3 })
28
- .settings({ number_of_replicas: 2 })
29
- .build();
30
- expect(result).toMatchInlineSnapshot(`
31
- {
32
- "settings": {
33
- "number_of_replicas": 2,
34
- },
35
- }
36
- `);
37
- });
38
- });
39
- describe('Mappings', () => {
40
- it('should build basic mappings', () => {
41
- const result = indexBuilder()
42
- .mappings({
43
- name: 'text',
44
- market_cap: 'float',
45
- asset_class: 'keyword'
46
- })
47
- .build();
48
- expect(result).toMatchInlineSnapshot(`
49
- {
50
- "mappings": {
51
- "properties": {
52
- "asset_class": {
53
- "type": "keyword",
54
- },
55
- "market_cap": {
56
- "type": "float",
57
- },
58
- "name": {
59
- "type": "text",
60
- },
61
- },
62
- },
63
- }
64
- `);
65
- });
66
- it('should build mappings with analyzers', () => {
67
- const result = indexBuilder()
68
- .mappings({
69
- name: text({
70
- analyzer: 'standard',
71
- search_analyzer: 'english'
72
- })
73
- })
74
- .build();
75
- expect(result).toMatchInlineSnapshot(`
76
- {
77
- "mappings": {
78
- "properties": {
79
- "name": {
80
- "analyzer": "standard",
81
- "search_analyzer": "english",
82
- "type": "text",
83
- },
84
- },
85
- },
86
- }
87
- `);
88
- });
89
- it('should build mappings with multi-fields', () => {
90
- const result = indexBuilder()
91
- .mappings({
92
- name: text({
93
- fields: {
94
- keyword: { type: 'keyword' },
95
- ngram: { type: 'text', analyzer: 'ngram' }
96
- }
97
- })
98
- })
99
- .build();
100
- expect(result).toMatchInlineSnapshot(`
101
- {
102
- "mappings": {
103
- "properties": {
104
- "name": {
105
- "fields": {
106
- "keyword": {
107
- "type": "keyword",
108
- },
109
- "ngram": {
110
- "analyzer": "ngram",
111
- "type": "text",
112
- },
113
- },
114
- "type": "text",
115
- },
116
- },
117
- },
118
- }
119
- `);
120
- });
121
- it('should build mappings with nested fields', () => {
122
- const result = indexBuilder()
123
- .mappings({
124
- tranches: nested({
125
- maturity: 'keyword',
126
- currency: 'keyword'
127
- })
128
- })
129
- .build();
130
- expect(result).toMatchInlineSnapshot(`
131
- {
132
- "mappings": {
133
- "properties": {
134
- "tranches": {
135
- "properties": {
136
- "currency": {
137
- "type": "keyword",
138
- },
139
- "maturity": {
140
- "type": "keyword",
141
- },
142
- },
143
- "type": "nested",
144
- },
145
- },
146
- },
147
- }
148
- `);
149
- });
150
- it('should build mappings with dense_vector', () => {
151
- const result = indexBuilder()
152
- .mappings({
153
- embedding: denseVector({
154
- dims: 384,
155
- index_options: {
156
- type: 'hnsw',
157
- m: 16,
158
- ef_construction: 100
159
- }
160
- })
161
- })
162
- .build();
163
- expect(result).toMatchInlineSnapshot(`
164
- {
165
- "mappings": {
166
- "properties": {
167
- "embedding": {
168
- "dims": 384,
169
- "index_options": {
170
- "ef_construction": 100,
171
- "m": 16,
172
- "type": "hnsw",
173
- },
174
- "type": "dense_vector",
175
- },
176
- },
177
- },
178
- }
179
- `);
180
- });
181
- it('should build mappings with dynamic strict', () => {
182
- const result = indexBuilder()
183
- .mappings({
184
- dynamic: 'strict',
185
- name: 'text'
186
- })
187
- .build();
188
- expect(result).toMatchInlineSnapshot(`
189
- {
190
- "mappings": {
191
- "dynamic": "strict",
192
- "properties": {
193
- "name": {
194
- "type": "text",
195
- },
196
- },
197
- },
198
- }
199
- `);
200
- });
201
- it('should build mappings with dynamic false', () => {
202
- const result = indexBuilder()
203
- .mappings({
204
- dynamic: false,
205
- name: 'text'
206
- })
207
- .build();
208
- expect(result).toMatchInlineSnapshot(`
209
- {
210
- "mappings": {
211
- "dynamic": false,
212
- "properties": {
213
- "name": {
214
- "type": "text",
215
- },
216
- },
217
- },
218
- }
219
- `);
220
- });
221
- it('should build mappings with dynamic runtime', () => {
222
- const result = indexBuilder()
223
- .mappings({
224
- dynamic: 'runtime',
225
- name: 'text'
226
- })
227
- .build();
228
- expect(result).toMatchInlineSnapshot(`
229
- {
230
- "mappings": {
231
- "dynamic": "runtime",
232
- "properties": {
233
- "name": {
234
- "type": "text",
235
- },
236
- },
237
- },
238
- }
239
- `);
240
- });
241
- it('should build mappings with dynamic_templates', () => {
242
- const result = indexBuilder()
243
- .mappings({
244
- dynamic_templates: [
245
- {
246
- strings_as_keywords: {
247
- match_mapping_type: 'string',
248
- mapping: { type: 'keyword' }
249
- }
250
- }
251
- ],
252
- name: 'text'
253
- })
254
- .build();
255
- expect(result).toMatchInlineSnapshot(`
256
- {
257
- "mappings": {
258
- "dynamic_templates": [
259
- {
260
- "strings_as_keywords": {
261
- "mapping": {
262
- "type": "keyword",
263
- },
264
- "match_mapping_type": "string",
265
- },
266
- },
267
- ],
268
- "properties": {
269
- "name": {
270
- "type": "text",
271
- },
272
- },
273
- },
274
- }
275
- `);
276
- });
277
- });
278
- describe('Field type coverage', () => {
279
- it('should support integer field type', () => {
280
- const result = indexBuilder().mappings({ count: 'integer' }).build();
281
- expect(result.mappings?.properties.count?.type).toBe('integer');
282
- });
283
- it('should support boolean field type', () => {
284
- const result = indexBuilder()
285
- .mappings({ active: 'boolean' })
286
- .build();
287
- expect(result.mappings?.properties.active?.type).toBe('boolean');
288
- });
289
- it('should support geo_point field type', () => {
290
- const result = indexBuilder()
291
- .mappings({ location: 'geo_point' })
292
- .build();
293
- expect(result.mappings?.properties.location?.type).toBe('geo_point');
294
- });
295
- it('should support date_range field type', () => {
296
- const result = indexBuilder()
297
- .mappings({ availability: 'date_range' })
298
- .build();
299
- expect(result.mappings?.properties.availability?.type).toBe('date_range');
300
- });
301
- it('should support scaled_float with scaling_factor', () => {
302
- const result = indexBuilder()
303
- .mappings({
304
- score: scaledFloat({ scaling_factor: 100 })
305
- })
306
- .build();
307
- expect(result).toMatchInlineSnapshot(`
308
- {
309
- "mappings": {
310
- "properties": {
311
- "score": {
312
- "scaling_factor": 100,
313
- "type": "scaled_float",
314
- },
315
- },
316
- },
317
- }
318
- `);
319
- });
320
- it('should support percolator field type', () => {
321
- const result = indexBuilder()
322
- .mappings({ query: percolator() })
323
- .build();
324
- expect(result.mappings?.properties.query?.type).toBe('percolator');
325
- });
326
- });
327
- describe('Field mapping properties', () => {
328
- it('should set boost on a field', () => {
329
- const result = indexBuilder()
330
- .mappings({
331
- name: text({ boost: 2 })
332
- })
333
- .build();
334
- expect(result).toMatchInlineSnapshot(`
335
- {
336
- "mappings": {
337
- "properties": {
338
- "name": {
339
- "boost": 2,
340
- "type": "text",
341
- },
342
- },
343
- },
344
- }
345
- `);
346
- });
347
- it('should set store and doc_values', () => {
348
- const result = indexBuilder()
349
- .mappings({
350
- asset_class: keyword({ store: true, doc_values: false })
351
- })
352
- .build();
353
- expect(result).toMatchInlineSnapshot(`
354
- {
355
- "mappings": {
356
- "properties": {
357
- "asset_class": {
358
- "doc_values": false,
359
- "store": true,
360
- "type": "keyword",
361
- },
362
- },
363
- },
364
- }
365
- `);
366
- });
367
- it('should set index to false', () => {
368
- const result = indexBuilder()
369
- .mappings({
370
- name: text({ index: false })
371
- })
372
- .build();
373
- expect(result).toMatchInlineSnapshot(`
374
- {
375
- "mappings": {
376
- "properties": {
377
- "name": {
378
- "index": false,
379
- "type": "text",
380
- },
381
- },
382
- },
383
- }
384
- `);
385
- });
386
- });
387
- describe('Settings', () => {
388
- it('should build basic settings', () => {
389
- const result = indexBuilder()
390
- .settings({
391
- number_of_shards: 2,
392
- number_of_replicas: 1
393
- })
394
- .build();
395
- expect(result).toMatchInlineSnapshot(`
396
- {
397
- "settings": {
398
- "number_of_replicas": 1,
399
- "number_of_shards": 2,
400
- },
401
- }
402
- `);
403
- });
404
- it('should configure refresh interval', () => {
405
- const result = indexBuilder()
406
- .settings({
407
- refresh_interval: '30s'
408
- })
409
- .build();
410
- expect(result).toMatchInlineSnapshot(`
411
- {
412
- "settings": {
413
- "refresh_interval": "30s",
414
- },
415
- }
416
- `);
417
- });
418
- it('should configure max result window', () => {
419
- const result = indexBuilder()
420
- .settings({
421
- max_result_window: 100000
422
- })
423
- .build();
424
- expect(result).toMatchInlineSnapshot(`
425
- {
426
- "settings": {
427
- "max_result_window": 100000,
428
- },
429
- }
430
- `);
431
- });
432
- });
433
- describe('Aliases', () => {
434
- it('should add simple alias', () => {
435
- const result = indexBuilder().alias('products_alias').build();
436
- expect(result).toMatchInlineSnapshot(`
437
- {
438
- "aliases": {
439
- "products_alias": {},
440
- },
441
- }
442
- `);
443
- });
444
- it('should add multiple aliases', () => {
445
- const result = indexBuilder()
446
- .alias('products_read')
447
- .alias('products_write')
448
- .build();
449
- expect(result).toMatchInlineSnapshot(`
450
- {
451
- "aliases": {
452
- "products_read": {},
453
- "products_write": {},
454
- },
455
- }
456
- `);
457
- });
458
- it('should add alias with filter', () => {
459
- const result = indexBuilder()
460
- .alias('electronics_alias', {
461
- filter: { term: { category: 'electronics' } }
462
- })
463
- .build();
464
- expect(result).toMatchInlineSnapshot(`
465
- {
466
- "aliases": {
467
- "electronics_alias": {
468
- "filter": {
469
- "term": {
470
- "category": "electronics",
471
- },
472
- },
473
- },
474
- },
475
- }
476
- `);
477
- });
478
- it('should add alias with routing', () => {
479
- const result = indexBuilder()
480
- .alias('routed_alias', { routing: 'shard-1' })
481
- .build();
482
- expect(result).toMatchInlineSnapshot(`
483
- {
484
- "aliases": {
485
- "routed_alias": {
486
- "routing": "shard-1",
487
- },
488
- },
489
- }
490
- `);
491
- });
492
- it('should add alias with is_write_index', () => {
493
- const result = indexBuilder()
494
- .alias('write_alias', { is_write_index: true })
495
- .build();
496
- expect(result).toMatchInlineSnapshot(`
497
- {
498
- "aliases": {
499
- "write_alias": {
500
- "is_write_index": true,
501
- },
502
- },
503
- }
504
- `);
505
- });
506
- });
507
- describe('Complete index configuration', () => {
508
- it('should combine mappings, settings, and aliases', () => {
509
- const result = indexBuilder()
510
- .mappings({
511
- name: text({ analyzer: 'standard' }),
512
- market_cap: 'float',
513
- asset_class: 'keyword',
514
- tags: 'keyword',
515
- listed_date: 'date'
516
- })
517
- .settings({
518
- number_of_shards: 2,
519
- number_of_replicas: 1,
520
- refresh_interval: '1s'
521
- })
522
- .alias('products_alias')
523
- .build();
524
- expect(result).toMatchInlineSnapshot(`
525
- {
526
- "aliases": {
527
- "products_alias": {},
528
- },
529
- "mappings": {
530
- "properties": {
531
- "asset_class": {
532
- "type": "keyword",
533
- },
534
- "listed_date": {
535
- "type": "date",
536
- },
537
- "market_cap": {
538
- "type": "float",
539
- },
540
- "name": {
541
- "analyzer": "standard",
542
- "type": "text",
543
- },
544
- "tags": {
545
- "type": "keyword",
546
- },
547
- },
548
- },
549
- "settings": {
550
- "number_of_replicas": 1,
551
- "number_of_shards": 2,
552
- "refresh_interval": "1s",
553
- },
554
- }
555
- `);
556
- });
557
- });
558
- describe('Real-world index configurations', () => {
559
- it('should build e-commerce product index', () => {
560
- const result = indexBuilder()
561
- .mappings({
562
- isin: 'keyword',
563
- name: text({
564
- analyzer: 'standard',
565
- fields: {
566
- keyword: { type: 'keyword' },
567
- suggest: { type: 'completion' }
568
- }
569
- }),
570
- sector: text({ analyzer: 'english' }),
571
- market_cap: 'float',
572
- asset_class: 'keyword',
573
- tags: 'keyword',
574
- listed_date: 'date'
575
- })
576
- .settings({
577
- number_of_shards: 3,
578
- number_of_replicas: 2,
579
- refresh_interval: '5s',
580
- max_result_window: 50000
581
- })
582
- .alias('products_live')
583
- .alias('products_search', {
584
- filter: { range: { market_cap: { gte: 0 } } }
585
- })
586
- .build();
587
- expect(result).toMatchInlineSnapshot(`
588
- {
589
- "aliases": {
590
- "products_live": {},
591
- "products_search": {
592
- "filter": {
593
- "range": {
594
- "market_cap": {
595
- "gte": 0,
596
- },
597
- },
598
- },
599
- },
600
- },
601
- "mappings": {
602
- "properties": {
603
- "asset_class": {
604
- "type": "keyword",
605
- },
606
- "isin": {
607
- "type": "keyword",
608
- },
609
- "listed_date": {
610
- "type": "date",
611
- },
612
- "market_cap": {
613
- "type": "float",
614
- },
615
- "name": {
616
- "analyzer": "standard",
617
- "fields": {
618
- "keyword": {
619
- "type": "keyword",
620
- },
621
- "suggest": {
622
- "type": "completion",
623
- },
624
- },
625
- "type": "text",
626
- },
627
- "sector": {
628
- "analyzer": "english",
629
- "type": "text",
630
- },
631
- "tags": {
632
- "type": "keyword",
633
- },
634
- },
635
- },
636
- "settings": {
637
- "max_result_window": 50000,
638
- "number_of_replicas": 2,
639
- "number_of_shards": 3,
640
- "refresh_interval": "5s",
641
- },
642
- }
643
- `);
644
- });
645
- it('should build vector search index', () => {
646
- const result = indexBuilder()
647
- .mappings({
648
- name: 'text',
649
- embedding: denseVector({
650
- dims: 768,
651
- index: true,
652
- index_options: {
653
- type: 'hnsw',
654
- m: 16,
655
- ef_construction: 200
656
- }
657
- })
658
- })
659
- .settings({
660
- number_of_shards: 1,
661
- number_of_replicas: 0
662
- })
663
- .build();
664
- expect(result).toMatchInlineSnapshot(`
665
- {
666
- "mappings": {
667
- "properties": {
668
- "embedding": {
669
- "dims": 768,
670
- "index": true,
671
- "index_options": {
672
- "ef_construction": 200,
673
- "m": 16,
674
- "type": "hnsw",
675
- },
676
- "type": "dense_vector",
677
- },
678
- "name": {
679
- "type": "text",
680
- },
681
- },
682
- },
683
- "settings": {
684
- "number_of_replicas": 0,
685
- "number_of_shards": 1,
686
- },
687
- }
688
- `);
689
- });
690
- it('should build time-series index', () => {
691
- const result = indexBuilder()
692
- .mappings({
693
- timestamp: 'date',
694
- level: 'keyword',
695
- message: 'text',
696
- source: 'keyword'
697
- })
698
- .settings({
699
- number_of_shards: 1,
700
- number_of_replicas: 1,
701
- refresh_interval: '30s'
702
- })
703
- .alias('logs_current')
704
- .build();
705
- expect(result).toMatchInlineSnapshot(`
706
- {
707
- "aliases": {
708
- "logs_current": {},
709
- },
710
- "mappings": {
711
- "properties": {
712
- "level": {
713
- "type": "keyword",
714
- },
715
- "message": {
716
- "type": "text",
717
- },
718
- "source": {
719
- "type": "keyword",
720
- },
721
- "timestamp": {
722
- "type": "date",
723
- },
724
- },
725
- },
726
- "settings": {
727
- "number_of_replicas": 1,
728
- "number_of_shards": 1,
729
- "refresh_interval": "30s",
730
- },
731
- }
732
- `);
733
- });
734
- });
735
- describe('Field helpers', () => {
736
- it('should resolve shorthand strings to field mappings', () => {
737
- const result = indexBuilder()
738
- .mappings({ name: 'text', count: 'integer' })
739
- .build();
740
- expect(result.mappings?.properties.name).toEqual({ type: 'text' });
741
- expect(result.mappings?.properties.count).toEqual({ type: 'integer' });
742
- });
743
- it('should support helpers called with no options', () => {
744
- const result = indexBuilder()
745
- .mappings({ name: text(), price: float(), active: boolean() })
746
- .build();
747
- expect(result.mappings?.properties.name).toEqual({ type: 'text' });
748
- expect(result.mappings?.properties.price).toEqual({ type: 'float' });
749
- expect(result.mappings?.properties.active).toEqual({ type: 'boolean' });
750
- });
751
- it('should mix shorthand strings and helpers', () => {
752
- const result = indexBuilder()
753
- .mappings({
754
- isin: 'keyword',
755
- name: text({ analyzer: 'standard' }),
756
- market_cap: 'float',
757
- embedding: denseVector({ dims: 384 })
758
- })
759
- .build();
760
- expect(result.mappings?.properties.isin).toEqual({ type: 'keyword' });
761
- expect(result.mappings?.properties.name).toEqual({
762
- type: 'text',
763
- analyzer: 'standard'
764
- });
765
- expect(result.mappings?.properties.market_cap).toEqual({ type: 'float' });
766
- expect(result.mappings?.properties.embedding).toEqual({
767
- type: 'dense_vector',
768
- dims: 384
769
- });
770
- });
771
- it('should support all numeric helpers', () => {
772
- const result = indexBuilder()
773
- .mappings({ a: 'long', b: 'short', c: 'byte', d: 'double' })
774
- .build();
775
- expect(result.mappings?.properties.a?.type).toBe('long');
776
- expect(result.mappings?.properties.b?.type).toBe('short');
777
- expect(result.mappings?.properties.c?.type).toBe('byte');
778
- expect(result.mappings?.properties.d?.type).toBe('double');
779
- });
780
- it('should support geo and completion helpers', () => {
781
- const result = indexBuilder()
782
- .mappings({
783
- location: geoPoint(),
784
- suggest: completion({ analyzer: 'simple' })
785
- })
786
- .build();
787
- expect(result.mappings?.properties.location).toEqual({
788
- type: 'geo_point'
789
- });
790
- expect(result.mappings?.properties.suggest).toEqual({
791
- type: 'completion',
792
- analyzer: 'simple'
793
- });
794
- });
795
- it('should support date helper with format', () => {
796
- const result = indexBuilder()
797
- .mappings({ created: date({ format: 'yyyy-MM-dd' }) })
798
- .build();
799
- expect(result.mappings?.properties.created).toEqual({
800
- type: 'date',
801
- format: 'yyyy-MM-dd'
802
- });
803
- });
804
- it('should support range type helpers', () => {
805
- const result = indexBuilder()
806
- .mappings({ availability: dateRange() })
807
- .build();
808
- expect(result.mappings?.properties.availability).toEqual({
809
- type: 'date_range'
810
- });
811
- });
812
- it('should support integer helper with options', () => {
813
- const result = indexBuilder()
814
- .mappings({ count: integer({ store: true }) })
815
- .build();
816
- expect(result.mappings?.properties.count).toEqual({
817
- type: 'integer',
818
- store: true
819
- });
820
- });
821
- it('should support halfFloat helper', () => {
822
- const result = indexBuilder()
823
- .mappings({ score: halfFloat() })
824
- .build();
825
- expect(result).toMatchInlineSnapshot(`
826
- {
827
- "mappings": {
828
- "properties": {
829
- "score": {
830
- "type": "half_float",
831
- },
832
- },
833
- },
834
- }
835
- `);
836
- });
837
- it('should support halfFloat helper with options', () => {
838
- const result = indexBuilder()
839
- .mappings({ score: halfFloat({ index: false }) })
840
- .build();
841
- expect(result).toMatchInlineSnapshot(`
842
- {
843
- "mappings": {
844
- "properties": {
845
- "score": {
846
- "index": false,
847
- "type": "half_float",
848
- },
849
- },
850
- },
851
- }
852
- `);
853
- });
854
- it('should support binary helper', () => {
855
- const result = indexBuilder().mappings({ blob: binary() }).build();
856
- expect(result).toMatchInlineSnapshot(`
857
- {
858
- "mappings": {
859
- "properties": {
860
- "blob": {
861
- "type": "binary",
862
- },
863
- },
864
- },
865
- }
866
- `);
867
- });
868
- it('should support ip helper', () => {
869
- const result = indexBuilder().mappings({ remote_ip: ip() }).build();
870
- expect(result).toMatchInlineSnapshot(`
871
- {
872
- "mappings": {
873
- "properties": {
874
- "remote_ip": {
875
- "type": "ip",
876
- },
877
- },
878
- },
879
- }
880
- `);
881
- });
882
- it('should support ip helper with options', () => {
883
- const result = indexBuilder()
884
- .mappings({ remote_ip: ip({ store: true }) })
885
- .build();
886
- expect(result).toMatchInlineSnapshot(`
887
- {
888
- "mappings": {
889
- "properties": {
890
- "remote_ip": {
891
- "store": true,
892
- "type": "ip",
893
- },
894
- },
895
- },
896
- }
897
- `);
898
- });
899
- it('should support geoShape helper', () => {
900
- const result = indexBuilder()
901
- .mappings({ boundary: geoShape() })
902
- .build();
903
- expect(result).toMatchInlineSnapshot(`
904
- {
905
- "mappings": {
906
- "properties": {
907
- "boundary": {
908
- "type": "geo_shape",
909
- },
910
- },
911
- },
912
- }
913
- `);
914
- });
915
- it('should support geoShape helper with options', () => {
916
- const result = indexBuilder()
917
- .mappings({ boundary: geoShape({ ignore_malformed: true }) })
918
- .build();
919
- expect(result).toMatchInlineSnapshot(`
920
- {
921
- "mappings": {
922
- "properties": {
923
- "boundary": {
924
- "ignore_malformed": true,
925
- "type": "geo_shape",
926
- },
927
- },
928
- },
929
- }
930
- `);
931
- });
932
- it('should support integerRange helper', () => {
933
- const result = indexBuilder()
934
- .mappings({ age_range: integerRange() })
935
- .build();
936
- expect(result).toMatchInlineSnapshot(`
937
- {
938
- "mappings": {
939
- "properties": {
940
- "age_range": {
941
- "type": "integer_range",
942
- },
943
- },
944
- },
945
- }
946
- `);
947
- });
948
- it('should support floatRange helper', () => {
949
- const result = indexBuilder()
950
- .mappings({ price_range: floatRange() })
951
- .build();
952
- expect(result).toMatchInlineSnapshot(`
953
- {
954
- "mappings": {
955
- "properties": {
956
- "price_range": {
957
- "type": "float_range",
958
- },
959
- },
960
- },
961
- }
962
- `);
963
- });
964
- it('should support longRange helper', () => {
965
- const result = indexBuilder()
966
- .mappings({ timestamp_range: longRange() })
967
- .build();
968
- expect(result).toMatchInlineSnapshot(`
969
- {
970
- "mappings": {
971
- "properties": {
972
- "timestamp_range": {
973
- "type": "long_range",
974
- },
975
- },
976
- },
977
- }
978
- `);
979
- });
980
- it('should support doubleRange helper', () => {
981
- const result = indexBuilder()
982
- .mappings({ score_range: doubleRange() })
983
- .build();
984
- expect(result).toMatchInlineSnapshot(`
985
- {
986
- "mappings": {
987
- "properties": {
988
- "score_range": {
989
- "type": "double_range",
990
- },
991
- },
992
- },
993
- }
994
- `);
995
- });
996
- it('should support range helpers with options', () => {
997
- const result = indexBuilder()
998
- .mappings({ availability: integerRange({ store: true }) })
999
- .build();
1000
- expect(result).toMatchInlineSnapshot(`
1001
- {
1002
- "mappings": {
1003
- "properties": {
1004
- "availability": {
1005
- "store": true,
1006
- "type": "integer_range",
1007
- },
1008
- },
1009
- },
1010
- }
1011
- `);
1012
- });
1013
- it('should support object helper with no arguments', () => {
1014
- const result = indexBuilder()
1015
- .mappings({ metadata: object() })
1016
- .build();
1017
- expect(result).toMatchInlineSnapshot(`
1018
- {
1019
- "mappings": {
1020
- "properties": {
1021
- "metadata": {
1022
- "type": "object",
1023
- },
1024
- },
1025
- },
1026
- }
1027
- `);
1028
- });
1029
- it('should support object helper with fields', () => {
1030
- const result = indexBuilder()
1031
- .mappings({
1032
- address: object({ street: 'text', city: 'keyword' })
1033
- })
1034
- .build();
1035
- expect(result).toMatchInlineSnapshot(`
1036
- {
1037
- "mappings": {
1038
- "properties": {
1039
- "address": {
1040
- "properties": {
1041
- "city": {
1042
- "type": "keyword",
1043
- },
1044
- "street": {
1045
- "type": "text",
1046
- },
1047
- },
1048
- "type": "object",
1049
- },
1050
- },
1051
- },
1052
- }
1053
- `);
1054
- });
1055
- it('should support object helper with enabled: false', () => {
1056
- const result = indexBuilder()
1057
- .mappings({ raw: object(undefined, { enabled: false }) })
1058
- .build();
1059
- expect(result).toMatchInlineSnapshot(`
1060
- {
1061
- "mappings": {
1062
- "properties": {
1063
- "raw": {
1064
- "enabled": false,
1065
- "type": "object",
1066
- },
1067
- },
1068
- },
1069
- }
1070
- `);
1071
- });
1072
- it('should support object helper with fields and enabled option', () => {
1073
- const result = indexBuilder()
1074
- .mappings({
1075
- address: object({ street: 'text' }, { enabled: true })
1076
- })
1077
- .build();
1078
- expect(result).toMatchInlineSnapshot(`
1079
- {
1080
- "mappings": {
1081
- "properties": {
1082
- "address": {
1083
- "enabled": true,
1084
- "properties": {
1085
- "street": {
1086
- "type": "text",
1087
- },
1088
- },
1089
- "type": "object",
1090
- },
1091
- },
1092
- },
1093
- }
1094
- `);
1095
- });
1096
- it('should support alias helper with path', () => {
1097
- const result = indexBuilder()
1098
- .mappings({ full_name: alias({ path: 'name' }) })
1099
- .build();
1100
- expect(result).toMatchInlineSnapshot(`
1101
- {
1102
- "mappings": {
1103
- "properties": {
1104
- "full_name": {
1105
- "path": "name",
1106
- "type": "alias",
1107
- },
1108
- },
1109
- },
1110
- }
1111
- `);
1112
- });
1113
- it('should support alias helper with no options', () => {
1114
- const result = indexBuilder()
1115
- .mappings({ full_name: alias() })
1116
- .build();
1117
- expect(result).toMatchInlineSnapshot(`
1118
- {
1119
- "mappings": {
1120
- "properties": {
1121
- "full_name": {
1122
- "type": "alias",
1123
- },
1124
- },
1125
- },
1126
- }
1127
- `);
1128
- });
1129
- });
1130
- describe('Undefined field guard', () => {
1131
- it('should skip fields with undefined values in mappings', () => {
1132
- const result = indexBuilder()
1133
- .mappings({ name: 'text', price: undefined })
1134
- .build();
1135
- expect(result).toMatchInlineSnapshot(`
1136
- {
1137
- "mappings": {
1138
- "properties": {
1139
- "name": {
1140
- "type": "text",
1141
- },
1142
- },
1143
- },
1144
- }
1145
- `);
1146
- });
1147
- });
1148
- });