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.
- package/README.md +98 -23
- package/dist/bulk.builder.d.ts +3 -123
- package/dist/bulk.builder.d.ts.map +1 -1
- package/dist/field.helpers.d.ts +45 -3
- package/dist/field.helpers.d.ts.map +1 -1
- package/dist/field.helpers.js +50 -9
- package/dist/field.types.d.ts +18 -1
- package/dist/field.types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/mapping.builder.d.ts +15 -6
- package/dist/mapping.builder.d.ts.map +1 -1
- package/dist/mapping.builder.js +1 -0
- package/dist/mapping.types.d.ts +44 -12
- package/dist/mapping.types.d.ts.map +1 -1
- package/dist/query.builder.d.ts.map +1 -1
- package/dist/query.builder.js +64 -64
- package/dist/query.types.d.ts +57 -5
- package/dist/query.types.d.ts.map +1 -1
- package/package.json +2 -3
- package/dist/__tests__/aggregation-builder.test.d.ts +0 -2
- package/dist/__tests__/aggregation-builder.test.d.ts.map +0 -1
- package/dist/__tests__/aggregation-builder.test.js +0 -622
- package/dist/__tests__/bulk.test.d.ts +0 -2
- package/dist/__tests__/bulk.test.d.ts.map +0 -1
- package/dist/__tests__/bulk.test.js +0 -679
- package/dist/__tests__/examples.test.d.ts +0 -2
- package/dist/__tests__/examples.test.d.ts.map +0 -1
- package/dist/__tests__/examples.test.js +0 -2123
- package/dist/__tests__/fixtures/finance.d.ts +0 -58
- package/dist/__tests__/fixtures/finance.d.ts.map +0 -1
- package/dist/__tests__/fixtures/finance.js +0 -73
- package/dist/__tests__/fixtures/legal.d.ts +0 -14
- package/dist/__tests__/fixtures/legal.d.ts.map +0 -1
- package/dist/__tests__/fixtures/legal.js +0 -27
- package/dist/__tests__/fixtures/real-estate.d.ts +0 -31
- package/dist/__tests__/fixtures/real-estate.d.ts.map +0 -1
- package/dist/__tests__/fixtures/real-estate.js +0 -39
- package/dist/__tests__/index-management.test.d.ts +0 -2
- package/dist/__tests__/index-management.test.d.ts.map +0 -1
- package/dist/__tests__/index-management.test.js +0 -1699
- package/dist/__tests__/integration/aggregation.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/aggregation.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/aggregation.integration.test.js +0 -188
- package/dist/__tests__/integration/bulk.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/bulk.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/bulk.integration.test.js +0 -90
- package/dist/__tests__/integration/fixtures/finance.d.ts +0 -37
- package/dist/__tests__/integration/fixtures/finance.d.ts.map +0 -1
- package/dist/__tests__/integration/fixtures/finance.js +0 -58
- package/dist/__tests__/integration/fixtures/legal.d.ts +0 -38
- package/dist/__tests__/integration/fixtures/legal.d.ts.map +0 -1
- package/dist/__tests__/integration/fixtures/legal.js +0 -65
- package/dist/__tests__/integration/fixtures/real-estate.d.ts +0 -17
- package/dist/__tests__/integration/fixtures/real-estate.d.ts.map +0 -1
- package/dist/__tests__/integration/fixtures/real-estate.js +0 -28
- package/dist/__tests__/integration/helpers.d.ts +0 -15
- package/dist/__tests__/integration/helpers.d.ts.map +0 -1
- package/dist/__tests__/integration/helpers.js +0 -21
- package/dist/__tests__/integration/index-management.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/index-management.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/index-management.integration.test.js +0 -67
- package/dist/__tests__/integration/multi-search.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/multi-search.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/multi-search.integration.test.js +0 -49
- package/dist/__tests__/integration/query.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/query.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/query.integration.test.js +0 -101
- package/dist/__tests__/integration/suggester.integration.test.d.ts +0 -2
- package/dist/__tests__/integration/suggester.integration.test.d.ts.map +0 -1
- package/dist/__tests__/integration/suggester.integration.test.js +0 -42
- package/dist/__tests__/multi-search.test.d.ts +0 -2
- package/dist/__tests__/multi-search.test.d.ts.map +0 -1
- package/dist/__tests__/multi-search.test.js +0 -325
- package/dist/__tests__/query-builder-extensions.test.d.ts +0 -2
- package/dist/__tests__/query-builder-extensions.test.d.ts.map +0 -1
- package/dist/__tests__/query-builder-extensions.test.js +0 -436
- package/dist/__tests__/query-builder.test.d.ts +0 -2
- package/dist/__tests__/query-builder.test.d.ts.map +0 -1
- package/dist/__tests__/query-builder.test.js +0 -5482
- package/dist/__tests__/settings-presets.test.d.ts +0 -2
- package/dist/__tests__/settings-presets.test.d.ts.map +0 -1
- package/dist/__tests__/settings-presets.test.js +0 -183
- package/dist/__tests__/suggester.test.d.ts +0 -2
- package/dist/__tests__/suggester.test.d.ts.map +0 -1
- package/dist/__tests__/suggester.test.js +0 -1006
package/README.md
CHANGED
|
@@ -134,23 +134,25 @@ query(productMappings)
|
|
|
134
134
|
|
|
135
135
|
### Conditional Building
|
|
136
136
|
|
|
137
|
-
Build queries dynamically based on runtime values
|
|
137
|
+
Build queries dynamically based on runtime values. `.when(condition, fn)` — the chain is never broken. When the condition is falsy, the builder is returned unchanged, so no extra clauses or arrays are added. If you already called `.bool()`, that empty wrapper is preserved.
|
|
138
|
+
|
|
139
|
+
`condition` resolves as: functions are called, booleans are used as-is, and any other value uses a nullish check (`!= null`) — so numeric `0` and empty string `''` are treated as truthy.
|
|
138
140
|
|
|
139
141
|
```typescript
|
|
140
|
-
const searchTerm =
|
|
141
|
-
const minPrice =
|
|
142
|
+
const searchTerm: string | undefined = param.searchTerm;
|
|
143
|
+
const minPrice: number | undefined = param.minPrice;
|
|
142
144
|
|
|
143
145
|
query(productMappings)
|
|
144
146
|
.bool()
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
.filter(q =>
|
|
149
|
-
q.when(minPrice, q => q.range('price', { gte: minPrice })) || q.matchAll()
|
|
150
|
-
)
|
|
147
|
+
.when(searchTerm, q => q.must(q2 => q2.match('name', searchTerm!)))
|
|
148
|
+
.when(minPrice, q => q.filter(q2 => q2.range('price', { gte: minPrice! })))
|
|
151
149
|
.build();
|
|
152
150
|
```
|
|
153
151
|
|
|
152
|
+
> **Note:** TypeScript cannot narrow closure variables inside callbacks. Even though `.when(searchTerm, fn)` guarantees the value is defined inside `fn`, you still need a non-null assertion (`!`) to satisfy the type checker.
|
|
153
|
+
>
|
|
154
|
+
> **Note:** When the condition is false, any already-introduced `.bool()` wrapper is preserved. A `.bool().when(false, fn)` chain produces `{ query: { bool: {} } }` — not an error, just an empty bool clause.
|
|
155
|
+
|
|
154
156
|
### Query Parameters
|
|
155
157
|
|
|
156
158
|
```typescript
|
|
@@ -602,6 +604,89 @@ Produces:
|
|
|
602
604
|
}
|
|
603
605
|
```
|
|
604
606
|
|
|
607
|
+
#### Object and Nested Fields
|
|
608
|
+
|
|
609
|
+
Use `object()` for structured sub-documents queried with dot-notation — the common case for addresses, names, and similar JSON-like objects. Use `nested()` for arrays of objects where cross-field queries within the same element must be accurate.
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
import { mappings, text, keyword, float, integer, boolean, object, nested, type Infer } from 'elasticlink';
|
|
613
|
+
|
|
614
|
+
const productMappings = mappings({
|
|
615
|
+
name: text(),
|
|
616
|
+
in_stock: boolean(),
|
|
617
|
+
|
|
618
|
+
// object() — single structured value, queried with dot-notation (no wrapper needed)
|
|
619
|
+
address: object({
|
|
620
|
+
street: text(),
|
|
621
|
+
city: keyword(),
|
|
622
|
+
country: keyword(),
|
|
623
|
+
}),
|
|
624
|
+
|
|
625
|
+
// nested() — array of objects; cross-field queries require the .nested() wrapper
|
|
626
|
+
variants: nested({
|
|
627
|
+
sku: keyword(),
|
|
628
|
+
color: keyword(),
|
|
629
|
+
price: float(),
|
|
630
|
+
stock: integer(),
|
|
631
|
+
}),
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// Infer<> produces the correct nested TypeScript types:
|
|
635
|
+
type Product = Infer<typeof productMappings>;
|
|
636
|
+
// {
|
|
637
|
+
// name: string;
|
|
638
|
+
// in_stock: boolean;
|
|
639
|
+
// address: { street: string; city: string; country: string };
|
|
640
|
+
// variants: Array<{ sku: string; color: string; price: number; stock: number }>;
|
|
641
|
+
// }
|
|
642
|
+
|
|
643
|
+
// object sub-fields — query with dot-notation directly
|
|
644
|
+
query(productMappings)
|
|
645
|
+
.bool()
|
|
646
|
+
.filter(q => q.term('address.country', 'US')) // ✅ 'address.country' is a keyword field
|
|
647
|
+
.filter(q => q.match('address.street', 'Main')) // ✅ 'address.street' is a text field
|
|
648
|
+
.build();
|
|
649
|
+
|
|
650
|
+
// nested sub-fields — must use .nested() wrapper; inner builder is fully typed
|
|
651
|
+
query(productMappings)
|
|
652
|
+
.nested('variants', q => q.term('color', 'black')) // ✅ 'color' is typed as keyword
|
|
653
|
+
.build();
|
|
654
|
+
|
|
655
|
+
query(productMappings)
|
|
656
|
+
.nested('variants', q => q.range('price', { lte: 150 }), { score_mode: 'min' })
|
|
657
|
+
.build();
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
> **Inner field names are relative.** Inside a `.nested()` callback, you write field names relative to the nested path (e.g. `'color'`, not `'variants.color'`). The library automatically qualifies them to the correct full path in the generated DSL.
|
|
661
|
+
|
|
662
|
+
Object and nested fields can be composed to any depth. A 2-level deep mapping works the same way:
|
|
663
|
+
|
|
664
|
+
```typescript
|
|
665
|
+
const orderMappings = mappings({
|
|
666
|
+
title: text(),
|
|
667
|
+
shipments: nested({
|
|
668
|
+
tracking: keyword(),
|
|
669
|
+
address: object({ // object() inside nested()
|
|
670
|
+
city: keyword(),
|
|
671
|
+
country: keyword(),
|
|
672
|
+
}),
|
|
673
|
+
}),
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
// Root-level fields are queried directly
|
|
677
|
+
query(orderMappings)
|
|
678
|
+
.term('title', 'urgent')
|
|
679
|
+
.build();
|
|
680
|
+
|
|
681
|
+
// Nested sub-fields use .nested(); dot-notation inside is relative to the nested path
|
|
682
|
+
query(orderMappings)
|
|
683
|
+
.nested('shipments', q => q.term('address.city', 'London')) // ✅ 'address.city' relative to 'shipments'
|
|
684
|
+
.build();
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
> **Why the difference?**
|
|
688
|
+
> `object` fields are stored inline in the parent document — Elasticsearch flattens their sub-fields and you query them directly. `nested` fields are stored as separate hidden documents to preserve the relationship between sub-fields within each array element. Without the `.nested()` wrapper, a query like `color=black AND price<50` could incorrectly match a product where different variants have those values.
|
|
689
|
+
|
|
605
690
|
**Field Helpers** (shorthand for common field types):
|
|
606
691
|
|
|
607
692
|
```typescript
|
|
@@ -967,20 +1052,10 @@ Produces:
|
|
|
967
1052
|
const buildDynamicQuery = (filters: SearchFilters) => {
|
|
968
1053
|
return query(productMappings)
|
|
969
1054
|
.bool()
|
|
970
|
-
.
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
)
|
|
975
|
-
.filter(q =>
|
|
976
|
-
q.when(filters.minPrice && filters.maxPrice,
|
|
977
|
-
q => q.range('price', { gte: filters.minPrice, lte: filters.maxPrice })
|
|
978
|
-
) || q.matchAll()
|
|
979
|
-
)
|
|
980
|
-
.filter(q =>
|
|
981
|
-
q.when(filters.category,
|
|
982
|
-
q => q.term('category', filters.category)
|
|
983
|
-
) || q.matchAll()
|
|
1055
|
+
.when(filters.searchTerm, q => q.must(q2 => q2.match('name', filters.searchTerm!, { boost: 2 })))
|
|
1056
|
+
.when(filters.category, q => q.filter(q2 => q2.term('category', filters.category!)))
|
|
1057
|
+
.when(filters.minPrice != null && filters.maxPrice != null,
|
|
1058
|
+
q => q.filter(q2 => q2.range('price', { gte: filters.minPrice!, lte: filters.maxPrice! }))
|
|
984
1059
|
)
|
|
985
1060
|
.from(filters.offset || 0)
|
|
986
1061
|
.size(filters.limit || 20)
|
package/dist/bulk.builder.d.ts
CHANGED
|
@@ -22,127 +22,7 @@ export declare const createBulkBuilder: <T>(operations?: any[]) => BulkBuilder<T
|
|
|
22
22
|
* .delete({ _index: 'products', _id: '4' })
|
|
23
23
|
* .build(); // POST to /_bulk with Content-Type: application/x-ndjson
|
|
24
24
|
*/
|
|
25
|
-
export declare const bulk: <M extends Record<string, FieldTypeString>>(_schema: MappingsSchema<M>) => BulkBuilder<{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
keyword: string;
|
|
29
|
-
constant_keyword: string;
|
|
30
|
-
wildcard: string;
|
|
31
|
-
long: number;
|
|
32
|
-
integer: number;
|
|
33
|
-
short: number;
|
|
34
|
-
byte: number;
|
|
35
|
-
float: number;
|
|
36
|
-
double: number;
|
|
37
|
-
half_float: number;
|
|
38
|
-
scaled_float: number;
|
|
39
|
-
date: string;
|
|
40
|
-
boolean: boolean;
|
|
41
|
-
binary: string;
|
|
42
|
-
ip: string;
|
|
43
|
-
geo_point: {
|
|
44
|
-
lat: number;
|
|
45
|
-
lon: number;
|
|
46
|
-
};
|
|
47
|
-
geo_shape: Record<string, unknown>;
|
|
48
|
-
dense_vector: number[];
|
|
49
|
-
completion: string;
|
|
50
|
-
search_as_you_type: string;
|
|
51
|
-
nested: unknown;
|
|
52
|
-
object: unknown;
|
|
53
|
-
flattened: Record<string, unknown>;
|
|
54
|
-
alias: unknown;
|
|
55
|
-
percolator: unknown;
|
|
56
|
-
integer_range: {
|
|
57
|
-
gte?: number;
|
|
58
|
-
lte?: number;
|
|
59
|
-
gt?: number;
|
|
60
|
-
lt?: number;
|
|
61
|
-
};
|
|
62
|
-
float_range: {
|
|
63
|
-
gte?: number;
|
|
64
|
-
lte?: number;
|
|
65
|
-
gt?: number;
|
|
66
|
-
lt?: number;
|
|
67
|
-
};
|
|
68
|
-
long_range: {
|
|
69
|
-
gte?: number;
|
|
70
|
-
lte?: number;
|
|
71
|
-
gt?: number;
|
|
72
|
-
lt?: number;
|
|
73
|
-
};
|
|
74
|
-
double_range: {
|
|
75
|
-
gte?: number;
|
|
76
|
-
lte?: number;
|
|
77
|
-
gt?: number;
|
|
78
|
-
lt?: number;
|
|
79
|
-
};
|
|
80
|
-
date_range: {
|
|
81
|
-
gte?: string;
|
|
82
|
-
lte?: string;
|
|
83
|
-
gt?: string;
|
|
84
|
-
lt?: string;
|
|
85
|
-
};
|
|
86
|
-
} ? {
|
|
87
|
-
text: string;
|
|
88
|
-
match_only_text: string;
|
|
89
|
-
keyword: string;
|
|
90
|
-
constant_keyword: string;
|
|
91
|
-
wildcard: string;
|
|
92
|
-
long: number;
|
|
93
|
-
integer: number;
|
|
94
|
-
short: number;
|
|
95
|
-
byte: number;
|
|
96
|
-
float: number;
|
|
97
|
-
double: number;
|
|
98
|
-
half_float: number;
|
|
99
|
-
scaled_float: number;
|
|
100
|
-
date: string;
|
|
101
|
-
boolean: boolean;
|
|
102
|
-
binary: string;
|
|
103
|
-
ip: string;
|
|
104
|
-
geo_point: {
|
|
105
|
-
lat: number;
|
|
106
|
-
lon: number;
|
|
107
|
-
};
|
|
108
|
-
geo_shape: Record<string, unknown>;
|
|
109
|
-
dense_vector: number[];
|
|
110
|
-
completion: string;
|
|
111
|
-
search_as_you_type: string;
|
|
112
|
-
nested: unknown;
|
|
113
|
-
object: unknown;
|
|
114
|
-
flattened: Record<string, unknown>;
|
|
115
|
-
alias: unknown;
|
|
116
|
-
percolator: unknown;
|
|
117
|
-
integer_range: {
|
|
118
|
-
gte?: number;
|
|
119
|
-
lte?: number;
|
|
120
|
-
gt?: number;
|
|
121
|
-
lt?: number;
|
|
122
|
-
};
|
|
123
|
-
float_range: {
|
|
124
|
-
gte?: number;
|
|
125
|
-
lte?: number;
|
|
126
|
-
gt?: number;
|
|
127
|
-
lt?: number;
|
|
128
|
-
};
|
|
129
|
-
long_range: {
|
|
130
|
-
gte?: number;
|
|
131
|
-
lte?: number;
|
|
132
|
-
gt?: number;
|
|
133
|
-
lt?: number;
|
|
134
|
-
};
|
|
135
|
-
double_range: {
|
|
136
|
-
gte?: number;
|
|
137
|
-
lte?: number;
|
|
138
|
-
gt?: number;
|
|
139
|
-
lt?: number;
|
|
140
|
-
};
|
|
141
|
-
date_range: {
|
|
142
|
-
gte?: string;
|
|
143
|
-
lte?: string;
|
|
144
|
-
gt?: string;
|
|
145
|
-
lt?: string;
|
|
146
|
-
};
|
|
147
|
-
}[M[K]] : unknown; }>;
|
|
25
|
+
export declare const bulk: <M extends Record<string, FieldTypeString>>(_schema: MappingsSchema<M>) => BulkBuilder<{
|
|
26
|
+
[x: string]: unknown;
|
|
27
|
+
}>;
|
|
148
28
|
//# sourceMappingURL=bulk.builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulk.builder.d.ts","sourceRoot":"","sources":["../src/bulk.builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAEjC,aAAY,GAAG,EAAO,KACrB,WAAW,CAAC,CAAC,CAiCd,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"bulk.builder.d.ts","sourceRoot":"","sources":["../src/bulk.builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAEjC,aAAY,GAAG,EAAO,KACrB,WAAW,CAAC,CAAC,CAiCd,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC;;EAC3C,CAAC"}
|
package/dist/field.helpers.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* embedding: denseVector({ dims: 384 }),
|
|
14
14
|
* });
|
|
15
15
|
*/
|
|
16
|
-
import type { TextFieldOptions, KeywordFieldOptions, NumericFieldOptions, ScaledFloatFieldOptions, DateFieldOptions, BooleanFieldOptions, DenseVectorFieldOptions,
|
|
16
|
+
import type { TextFieldOptions, KeywordFieldOptions, NumericFieldOptions, ScaledFloatFieldOptions, DateFieldOptions, BooleanFieldOptions, DenseVectorFieldOptions, ObjectFieldOptions, CompletionFieldOptions, GeoPointFieldOptions, GeoShapeFieldOptions, AliasFieldOptions, IpFieldOptions, RangeFieldOptions, MatchOnlyTextFieldOptions, SearchAsYouTypeFieldOptions, ConstantKeywordFieldOptions, WildcardFieldOptions, FlattenedFieldOptions, FieldMappingWithLiteralType, TextFieldMapping, KeywordFieldMapping, LongFieldMapping, IntegerFieldMapping, ShortFieldMapping, ByteFieldMapping, DoubleFieldMapping, FloatFieldMapping, HalfFloatFieldMapping, ScaledFloatFieldMapping, DateFieldMapping, BooleanFieldMapping, BinaryFieldMapping, IpFieldMapping, DenseVectorFieldMapping, GeoPointFieldMapping, GeoShapeFieldMapping, CompletionFieldMapping, TypedNestedFieldMapping, TypedObjectFieldMapping, AliasFieldMapping, PercolatorFieldMapping, IntegerRangeFieldMapping, FloatRangeFieldMapping, LongRangeFieldMapping, DoubleRangeFieldMapping, DateRangeFieldMapping, MatchOnlyTextFieldMapping, SearchAsYouTypeFieldMapping, ConstantKeywordFieldMapping, WildcardFieldMapping, FlattenedFieldMapping } from './field.types.js';
|
|
17
17
|
export declare const text: (options?: TextFieldOptions) => TextFieldMapping;
|
|
18
18
|
export declare const keyword: (options?: KeywordFieldOptions) => KeywordFieldMapping;
|
|
19
19
|
export declare const long: (options?: NumericFieldOptions) => LongFieldMapping;
|
|
@@ -64,8 +64,50 @@ export declare const quantizedDenseVector: (options?: DenseVectorFieldOptions) =
|
|
|
64
64
|
export declare const geoPoint: (options?: GeoPointFieldOptions) => GeoPointFieldMapping;
|
|
65
65
|
export declare const geoShape: (options?: GeoShapeFieldOptions) => GeoShapeFieldMapping;
|
|
66
66
|
export declare const completion: (options?: CompletionFieldOptions) => CompletionFieldMapping;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Object field — for JSON-like structured documents where sub-fields are queried with dot-notation.
|
|
69
|
+
*
|
|
70
|
+
* The most common way to model structured data (e.g. `{ address: { city, zip } }`).
|
|
71
|
+
* Sub-fields are indexed inline within the parent document — no special query wrapper needed.
|
|
72
|
+
* Query sub-fields directly using dot-notation: `.term('address.city', 'NYC')`.
|
|
73
|
+
*
|
|
74
|
+
* Use `nested()` instead when you have **arrays of objects** and need cross-field queries
|
|
75
|
+
* within each element to be accurate (e.g. tags with both a label and weight).
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const m = mappings({
|
|
79
|
+
* address: object({
|
|
80
|
+
* street: text(),
|
|
81
|
+
* city: keyword(),
|
|
82
|
+
* zip: keyword(),
|
|
83
|
+
* }),
|
|
84
|
+
* });
|
|
85
|
+
* query(m).term('address.city', 'NYC').build();
|
|
86
|
+
*/
|
|
87
|
+
export declare function object<F extends Record<string, FieldMappingWithLiteralType>>(fields: F, options?: ObjectFieldOptions): TypedObjectFieldMapping<F>;
|
|
88
|
+
/**
|
|
89
|
+
* Nested field — for **arrays of objects** where cross-field queries within each element must be accurate.
|
|
90
|
+
*
|
|
91
|
+
* Each nested object is stored as a separate hidden Elasticsearch document, preserving the
|
|
92
|
+
* relationship between sub-fields within each element. Without `nested`, Elasticsearch flattens
|
|
93
|
+
* array sub-fields and loses which values belong to the same element.
|
|
94
|
+
*
|
|
95
|
+
* Queries on nested fields **must** use the `.nested()` query builder method — direct dot-notation
|
|
96
|
+
* queries will not find nested documents.
|
|
97
|
+
*
|
|
98
|
+
* Use `object()` instead for single structured objects (addresses, names, etc.) — it is simpler,
|
|
99
|
+
* more efficient, and does not require a query wrapper.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const m = mappings({
|
|
103
|
+
* tags: nested({
|
|
104
|
+
* label: keyword(),
|
|
105
|
+
* weight: float(),
|
|
106
|
+
* }),
|
|
107
|
+
* });
|
|
108
|
+
* query(m).nested('tags', q => q.term('label', 'sale')).build();
|
|
109
|
+
*/
|
|
110
|
+
export declare function nested<F extends Record<string, FieldMappingWithLiteralType>>(fields: F): TypedNestedFieldMapping<F>;
|
|
69
111
|
export declare const alias: (options: AliasFieldOptions) => AliasFieldMapping;
|
|
70
112
|
export declare const percolator: () => PercolatorFieldMapping;
|
|
71
113
|
export declare const integerRange: (options?: RangeFieldOptions) => IntegerRangeFieldMapping;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.helpers.d.ts","sourceRoot":"","sources":["../src/field.helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"field.helpers.d.ts","sourceRoot":"","sources":["../src/field.helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,iBAA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O,MAAM,SAAS,GAAI,UAAU,iBAAiB,KAAG,qBAGtD,CAAC;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,iBAAiB,KAAG,uBAGxD,CAAC;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,iBAAiB,KAAG,qBAGtD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,yBAAyB,KAAG,yBAGlE,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,2BAA2B,KAAG,2BAGtE,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,2BAA2B,KAAG,2BAGtE,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,oBAAoB,KAAG,oBAG7D,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,qBAAqB,KAAG,qBAG1D,CAAC"}
|
package/dist/field.helpers.js
CHANGED
|
@@ -128,15 +128,56 @@ export const completion = (options) => ({
|
|
|
128
128
|
...options
|
|
129
129
|
});
|
|
130
130
|
// Structured
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Object field — for JSON-like structured documents where sub-fields are queried with dot-notation.
|
|
133
|
+
*
|
|
134
|
+
* The most common way to model structured data (e.g. `{ address: { city, zip } }`).
|
|
135
|
+
* Sub-fields are indexed inline within the parent document — no special query wrapper needed.
|
|
136
|
+
* Query sub-fields directly using dot-notation: `.term('address.city', 'NYC')`.
|
|
137
|
+
*
|
|
138
|
+
* Use `nested()` instead when you have **arrays of objects** and need cross-field queries
|
|
139
|
+
* within each element to be accurate (e.g. tags with both a label and weight).
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const m = mappings({
|
|
143
|
+
* address: object({
|
|
144
|
+
* street: text(),
|
|
145
|
+
* city: keyword(),
|
|
146
|
+
* zip: keyword(),
|
|
147
|
+
* }),
|
|
148
|
+
* });
|
|
149
|
+
* query(m).term('address.city', 'NYC').build();
|
|
150
|
+
*/
|
|
151
|
+
export function object(fields, options) {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
return { type: 'object', ...(options ?? {}), properties: fields };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Nested field — for **arrays of objects** where cross-field queries within each element must be accurate.
|
|
157
|
+
*
|
|
158
|
+
* Each nested object is stored as a separate hidden Elasticsearch document, preserving the
|
|
159
|
+
* relationship between sub-fields within each element. Without `nested`, Elasticsearch flattens
|
|
160
|
+
* array sub-fields and loses which values belong to the same element.
|
|
161
|
+
*
|
|
162
|
+
* Queries on nested fields **must** use the `.nested()` query builder method — direct dot-notation
|
|
163
|
+
* queries will not find nested documents.
|
|
164
|
+
*
|
|
165
|
+
* Use `object()` instead for single structured objects (addresses, names, etc.) — it is simpler,
|
|
166
|
+
* more efficient, and does not require a query wrapper.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const m = mappings({
|
|
170
|
+
* tags: nested({
|
|
171
|
+
* label: keyword(),
|
|
172
|
+
* weight: float(),
|
|
173
|
+
* }),
|
|
174
|
+
* });
|
|
175
|
+
* query(m).nested('tags', q => q.term('label', 'sale')).build();
|
|
176
|
+
*/
|
|
177
|
+
export function nested(fields) {
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
+
return { type: 'nested', properties: fields };
|
|
180
|
+
}
|
|
140
181
|
// Alias
|
|
141
182
|
export const alias = (options) => ({
|
|
142
183
|
type: 'alias',
|
package/dist/field.types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Each helper function returns a mapping with a literal `type` field,
|
|
4
4
|
* enabling compile-time field-type inference in the query builder.
|
|
5
5
|
*/
|
|
6
|
-
import type { FieldMapping } from './index-management.types.js';
|
|
6
|
+
import type { FieldMapping, FieldTypeString } from './index-management.types.js';
|
|
7
7
|
/** Options for text fields */
|
|
8
8
|
export type TextFieldOptions = {
|
|
9
9
|
analyzer?: string;
|
|
@@ -184,6 +184,23 @@ export type FlattenedFieldOptions = {
|
|
|
184
184
|
export type TypedFieldMapping<T extends string> = Omit<FieldMapping, 'type'> & {
|
|
185
185
|
type: T;
|
|
186
186
|
};
|
|
187
|
+
export type FieldMappingWithLiteralType = FieldMapping & {
|
|
188
|
+
type: FieldTypeString;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Typed variant of `NestedFieldMapping` carrying sub-field type info at compile time.
|
|
192
|
+
* Produced when `nested()` is called with a typed field map.
|
|
193
|
+
*/
|
|
194
|
+
export type TypedNestedFieldMapping<F extends Record<string, FieldMappingWithLiteralType>> = NestedFieldMapping & Readonly<{
|
|
195
|
+
_subFields: F;
|
|
196
|
+
}>;
|
|
197
|
+
/**
|
|
198
|
+
* Typed variant of `ObjectFieldMapping` carrying sub-field type info at compile time.
|
|
199
|
+
* Produced when `object()` is called with a typed field map.
|
|
200
|
+
*/
|
|
201
|
+
export type TypedObjectFieldMapping<F extends Record<string, FieldMappingWithLiteralType>> = ObjectFieldMapping & Readonly<{
|
|
202
|
+
_subFields: F;
|
|
203
|
+
}>;
|
|
187
204
|
export type TextFieldMapping = TypedFieldMapping<'text'>;
|
|
188
205
|
export type KeywordFieldMapping = TypedFieldMapping<'keyword'>;
|
|
189
206
|
export type LongFieldMapping = TypedFieldMapping<'long'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.types.d.ts","sourceRoot":"","sources":["../src/field.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"field.types.d.ts","sourceRoot":"","sources":["../src/field.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO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Ae,CAAC,CAAC;AAC1E,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;AACtE,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACpE,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;AACxE,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACpE,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AAC7E,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;AAClF,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;AAChF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;AACjE,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type { AggregationBuilder } from './aggregation.types.js';
|
|
|
7
7
|
export { mappings } from './mapping.builder.js';
|
|
8
8
|
export { text, keyword, long, integer, short, byte, double, float, halfFloat, scaledFloat, date, boolean, binary, ip, denseVector, geoPoint, geoShape, completion, nested, object, alias, percolator, integerRange, floatRange, longRange, doubleRange, dateRange, matchOnlyText, searchAsYouType, constantKeyword, wildcardField, flattened, quantizedDenseVector } from './field.helpers.js';
|
|
9
9
|
export type { MappingsSchema, Infer, FieldsOfType, TextFields, KeywordFields, NumericFields, DateFields, BooleanFields, GeoPointFields, VectorFields, IpFields } from './mapping.types.js';
|
|
10
|
+
export type { FieldMappingWithLiteralType, TypedNestedFieldMapping, TypedObjectFieldMapping } from './field.types.js';
|
|
10
11
|
export { msearch } from './multi-search.builder.js';
|
|
11
12
|
export type { MSearchBuilder } from './multi-search.types.js';
|
|
12
13
|
export { bulk } from './bulk.builder.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAC7D,SAAS,cAAc,CAAC,CAAC,CAAC,EAC1B,eAAc,OAAc,+CAC6B,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,OAAO,EACP,KAAK,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,SAAS,EACT,WAAW,EACX,IAAI,EACJ,OAAO,EACP,MAAM,EACN,EAAE,EACF,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,SAAS,EACT,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,cAAc,EACd,KAAK,EACL,YAAY,EACZ,UAAU,EACV,aAAa,EACb,aAAa,EACb,UAAU,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACT,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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CAAC;AAG9D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -24,14 +24,23 @@
|
|
|
24
24
|
* _source: { excludes: ['embedding'] },
|
|
25
25
|
* });
|
|
26
26
|
*/
|
|
27
|
-
import type { FieldMapping, FieldTypeString } from './index-management.types.js';
|
|
28
27
|
import type { MappingOptions, MappingsSchema } from './mapping.types.js';
|
|
29
|
-
type FieldMappingWithLiteralType
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
import type { FieldMappingWithLiteralType } from './field.types.js';
|
|
29
|
+
type UnionToIntersection<U> = (U extends unknown ? (x: U) => never : never) extends (x: infer I) => never ? I : never;
|
|
30
|
+
type FlattenSubFields<Prefix extends string, F extends Record<string, FieldMappingWithLiteralType>> = UnionToIntersection<{
|
|
31
|
+
[K in keyof F & string]: {
|
|
32
|
+
[Key in `${Prefix}.${K}`]: F[K]['type'];
|
|
33
|
+
} & (F[K] extends {
|
|
34
|
+
_subFields: infer Sub extends Record<string, FieldMappingWithLiteralType>;
|
|
35
|
+
} ? FlattenSubFields<`${Prefix}.${K}`, Sub> : Record<never, never>);
|
|
36
|
+
}[keyof F & string]>;
|
|
32
37
|
type ExtractFieldTypes<F extends Record<string, FieldMappingWithLiteralType>> = {
|
|
33
38
|
[K in keyof F]: F[K]['type'];
|
|
34
|
-
}
|
|
35
|
-
|
|
39
|
+
} & UnionToIntersection<{
|
|
40
|
+
[K in keyof F & string]: F[K] extends {
|
|
41
|
+
_subFields: infer Sub extends Record<string, FieldMappingWithLiteralType>;
|
|
42
|
+
} ? FlattenSubFields<K, Sub> : Record<never, never>;
|
|
43
|
+
}[keyof F & string]>;
|
|
44
|
+
export declare const mappings: <F extends Record<string, FieldMappingWithLiteralType>>(fields: F, options?: MappingOptions) => MappingsSchema<ExtractFieldTypes<F>, F>;
|
|
36
45
|
export {};
|
|
37
46
|
//# sourceMappingURL=mapping.builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.builder.d.ts","sourceRoot":"","sources":["../src/mapping.builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;
|
|
1
|
+
{"version":3,"file":"mapping.builder.d.ts","sourceRoot":"","sources":["../src/mapping.builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAEpE,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AAEtH,KAAK,gBAAgB,CACnB,MAAM,SAAS,MAAM,EACrB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,IACnD,mBAAmB,CACrB;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG;SAAG,GAAG,IAAI,GAAG,MAAM,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;KAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QACnF,UAAU,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