elasticlink 0.8.0-beta → 1.0.0-beta.2
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 +631 -819
- package/dist/index.cjs +1528 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1890 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1889 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1474 -18
- package/dist/index.js.map +1 -0
- package/package.json +25 -19
- package/dist/aggregation.builder.d.ts +0 -6
- package/dist/aggregation.builder.d.ts.map +0 -1
- package/dist/aggregation.builder.js +0 -64
- package/dist/aggregation.types.d.ts +0 -173
- package/dist/aggregation.types.d.ts.map +0 -1
- package/dist/aggregation.types.js +0 -6
- package/dist/bulk.builder.d.ts +0 -28
- package/dist/bulk.builder.d.ts.map +0 -1
- package/dist/bulk.builder.js +0 -51
- package/dist/bulk.types.d.ts +0 -46
- package/dist/bulk.types.d.ts.map +0 -1
- package/dist/bulk.types.js +0 -6
- package/dist/field.helpers.d.ts +0 -167
- package/dist/field.helpers.d.ts.map +0 -1
- package/dist/field.helpers.js +0 -282
- package/dist/field.types.d.ts +0 -255
- package/dist/field.types.d.ts.map +0 -1
- package/dist/field.types.js +0 -6
- package/dist/index-management.builder.d.ts +0 -33
- package/dist/index-management.builder.d.ts.map +0 -1
- package/dist/index-management.builder.js +0 -64
- package/dist/index-management.types.d.ts +0 -126
- package/dist/index-management.types.d.ts.map +0 -1
- package/dist/index-management.types.js +0 -6
- package/dist/mapping.builder.d.ts +0 -46
- package/dist/mapping.builder.d.ts.map +0 -1
- package/dist/mapping.builder.js +0 -39
- package/dist/mapping.types.d.ts +0 -160
- package/dist/mapping.types.d.ts.map +0 -1
- package/dist/mapping.types.js +0 -6
- package/dist/multi-search.builder.d.ts +0 -22
- package/dist/multi-search.builder.d.ts.map +0 -1
- package/dist/multi-search.builder.js +0 -39
- package/dist/multi-search.types.d.ts +0 -36
- package/dist/multi-search.types.d.ts.map +0 -1
- package/dist/multi-search.types.js +0 -6
- package/dist/query.builder.d.ts +0 -4
- package/dist/query.builder.d.ts.map +0 -1
- package/dist/query.builder.js +0 -264
- package/dist/query.types.d.ts +0 -324
- package/dist/query.types.d.ts.map +0 -1
- package/dist/query.types.js +0 -7
- package/dist/settings.presets.d.ts +0 -98
- package/dist/settings.presets.d.ts.map +0 -1
- package/dist/settings.presets.js +0 -115
- package/dist/suggester.builder.d.ts +0 -23
- package/dist/suggester.builder.d.ts.map +0 -1
- package/dist/suggester.builder.js +0 -51
- package/dist/suggester.types.d.ts +0 -50
- package/dist/suggester.types.d.ts.map +0 -1
- package/dist/suggester.types.js +0 -6
- package/dist/vector.types.d.ts +0 -17
- package/dist/vector.types.d.ts.map +0 -1
- package/dist/vector.types.js +0 -6
|
@@ -1 +0,0 @@
|
|
|
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/bulk.builder.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bulk API builder
|
|
3
|
-
* Enables batching multiple index/create/update/delete operations
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Creates a bulk operations builder
|
|
7
|
-
* @returns BulkBuilder instance
|
|
8
|
-
*/
|
|
9
|
-
export const createBulkBuilder = (
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
operations = []) => ({
|
|
12
|
-
index: (doc, meta = {}) => {
|
|
13
|
-
return createBulkBuilder([...operations, { index: meta }, doc]);
|
|
14
|
-
},
|
|
15
|
-
create: (doc, meta = {}) => {
|
|
16
|
-
return createBulkBuilder([...operations, { create: meta }, doc]);
|
|
17
|
-
},
|
|
18
|
-
update: (meta) => {
|
|
19
|
-
const { doc, script, upsert, doc_as_upsert, ...header } = meta;
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
const updateDoc = {
|
|
22
|
-
...(doc && { doc }),
|
|
23
|
-
...(script && { script }),
|
|
24
|
-
...(upsert && { upsert }),
|
|
25
|
-
...(doc_as_upsert !== undefined && { doc_as_upsert })
|
|
26
|
-
};
|
|
27
|
-
return createBulkBuilder([...operations, { update: header }, updateDoc]);
|
|
28
|
-
},
|
|
29
|
-
delete: (meta) => {
|
|
30
|
-
return createBulkBuilder([...operations, { delete: meta }]);
|
|
31
|
-
},
|
|
32
|
-
// eslint-disable-next-line functional/functional-parameters
|
|
33
|
-
build: () => {
|
|
34
|
-
return `${operations.map((op) => JSON.stringify(op)).join('\n')}\n`;
|
|
35
|
-
},
|
|
36
|
-
// eslint-disable-next-line functional/functional-parameters
|
|
37
|
-
buildArray: () => operations
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* Create a new bulk operations builder.
|
|
41
|
-
* `.build()` returns an NDJSON string (newline-delimited JSON) ready to POST to `/_bulk`.
|
|
42
|
-
* `.buildArray()` returns the raw operation objects if you need to inspect or transform them.
|
|
43
|
-
* @example
|
|
44
|
-
* const ndjson = bulk(productMappings)
|
|
45
|
-
* .index({ id: '1', name: 'Product 1' }, { _index: 'products', _id: '1' })
|
|
46
|
-
* .create({ id: '2', name: 'Product 2' }, { _index: 'products', _id: '2' })
|
|
47
|
-
* .update({ _index: 'products', _id: '3', doc: { name: 'Updated' } })
|
|
48
|
-
* .delete({ _index: 'products', _id: '4' })
|
|
49
|
-
* .build(); // POST to /_bulk with Content-Type: application/x-ndjson
|
|
50
|
-
*/
|
|
51
|
-
export const bulk = (_schema) => createBulkBuilder();
|
package/dist/bulk.types.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for Bulk API
|
|
3
|
-
* Derived from official @elastic/elasticsearch types for accuracy and completeness.
|
|
4
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
5
|
-
*/
|
|
6
|
-
import type { BulkIndexOperation, BulkCreateOperation, BulkUpdateOperation, BulkUpdateAction, BulkDeleteOperation } from '@elastic/elasticsearch/lib/api/types';
|
|
7
|
-
/**
|
|
8
|
-
* Metadata for bulk index operation — re-exported from official @elastic/elasticsearch types
|
|
9
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
10
|
-
*/
|
|
11
|
-
export type BulkIndexMeta = BulkIndexOperation;
|
|
12
|
-
/**
|
|
13
|
-
* Metadata for bulk create operation — re-exported from official @elastic/elasticsearch types
|
|
14
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
15
|
-
*/
|
|
16
|
-
export type BulkCreateMeta = BulkCreateOperation;
|
|
17
|
-
/**
|
|
18
|
-
* Metadata for bulk update operation.
|
|
19
|
-
* Combines official BulkUpdateOperation (header) with BulkUpdateAction (body) for ergonomic API.
|
|
20
|
-
* The builder splits these into separate header and body when building the bulk request.
|
|
21
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
22
|
-
*/
|
|
23
|
-
export type BulkUpdateMeta<T> = BulkUpdateOperation & BulkUpdateAction<T, Partial<T>>;
|
|
24
|
-
/**
|
|
25
|
-
* Metadata for bulk delete operation — re-exported from official @elastic/elasticsearch types
|
|
26
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
|
|
27
|
-
*/
|
|
28
|
-
export type BulkDeleteMeta = BulkDeleteOperation;
|
|
29
|
-
/**
|
|
30
|
-
* Bulk operations builder interface
|
|
31
|
-
*/
|
|
32
|
-
export type BulkBuilder<T> = {
|
|
33
|
-
/** Index a document (create or replace) */
|
|
34
|
-
index: (doc: T, meta?: BulkIndexMeta) => BulkBuilder<T>;
|
|
35
|
-
/** Create a new document (fails if already exists) */
|
|
36
|
-
create: (doc: T, meta?: BulkCreateMeta) => BulkBuilder<T>;
|
|
37
|
-
/** Update an existing document */
|
|
38
|
-
update: (meta: BulkUpdateMeta<T>) => BulkBuilder<T>;
|
|
39
|
-
/** Delete a document */
|
|
40
|
-
delete: (meta: BulkDeleteMeta) => BulkBuilder<T>;
|
|
41
|
-
/** Build as NDJSON string format for Elasticsearch */
|
|
42
|
-
build: () => string;
|
|
43
|
-
/** Build as array of objects */
|
|
44
|
-
buildArray: () => any[];
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=bulk.types.d.ts.map
|
package/dist/bulk.types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bulk.types.d.ts","sourceRoot":"","sources":["../src/bulk.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,sCAAsC,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,mBAAmB,GAAG,gBAAgB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,2CAA2C;IAC3C,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,aAAa,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IACxD,sDAAsD;IACtD,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IAC1D,kCAAkC;IAClC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IACpD,wBAAwB;IACxB,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;IACjD,sDAAsD;IACtD,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,gCAAgC;IAEhC,UAAU,EAAE,MAAM,GAAG,EAAE,CAAC;CACzB,CAAC"}
|
package/dist/bulk.types.js
DELETED
package/dist/field.helpers.d.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Field type helper functions for ergonomic index mapping definitions.
|
|
3
|
-
* Each helper returns a narrowly-typed mapping with a literal `type` field,
|
|
4
|
-
* enabling compile-time field-type inference in the query builder.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { text, keyword, denseVector, mappings } from 'elasticlink';
|
|
8
|
-
*
|
|
9
|
-
* const productMappings = mappings({
|
|
10
|
-
* name: text({ analyzer: 'standard' }),
|
|
11
|
-
* price: float(),
|
|
12
|
-
* category: keyword(),
|
|
13
|
-
* embedding: denseVector({ dims: 384 }),
|
|
14
|
-
* });
|
|
15
|
-
*/
|
|
16
|
-
import type { TextFieldOptions, KeywordFieldOptions, NumericFieldOptions, UnsignedLongFieldOptions, ScaledFloatFieldOptions, DateFieldOptions, BooleanFieldOptions, DenseVectorFieldOptions, SemanticTextFieldOptions, 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, SparseVectorFieldMapping, SemanticTextFieldMapping, UnsignedLongFieldMapping, GeoPointFieldMapping, GeoShapeFieldMapping, CompletionFieldMapping, TypedNestedFieldMapping, TypedObjectFieldMapping, AliasFieldMapping, PercolatorFieldMapping, IntegerRangeFieldMapping, FloatRangeFieldMapping, LongRangeFieldMapping, DoubleRangeFieldMapping, DateRangeFieldMapping, MatchOnlyTextFieldMapping, SearchAsYouTypeFieldMapping, ConstantKeywordFieldMapping, WildcardFieldMapping, FlattenedFieldMapping } from './field.types.js';
|
|
17
|
-
export declare const text: (options?: TextFieldOptions) => TextFieldMapping;
|
|
18
|
-
export declare const keyword: (options?: KeywordFieldOptions) => KeywordFieldMapping;
|
|
19
|
-
export declare const long: (options?: NumericFieldOptions) => LongFieldMapping;
|
|
20
|
-
export declare const integer: (options?: NumericFieldOptions) => IntegerFieldMapping;
|
|
21
|
-
export declare const short: (options?: NumericFieldOptions) => ShortFieldMapping;
|
|
22
|
-
export declare const byte: (options?: NumericFieldOptions) => ByteFieldMapping;
|
|
23
|
-
export declare const double: (options?: NumericFieldOptions) => DoubleFieldMapping;
|
|
24
|
-
export declare const float: (options?: NumericFieldOptions) => FloatFieldMapping;
|
|
25
|
-
export declare const halfFloat: (options?: NumericFieldOptions) => HalfFloatFieldMapping;
|
|
26
|
-
export declare const scaledFloat: (options?: ScaledFloatFieldOptions) => ScaledFloatFieldMapping;
|
|
27
|
-
export declare const date: (options?: DateFieldOptions) => DateFieldMapping;
|
|
28
|
-
export declare const boolean: (options?: BooleanFieldOptions) => BooleanFieldMapping;
|
|
29
|
-
export declare const binary: () => BinaryFieldMapping;
|
|
30
|
-
export declare const ip: (options?: IpFieldOptions) => IpFieldMapping;
|
|
31
|
-
export declare const denseVector: (options?: DenseVectorFieldOptions) => DenseVectorFieldMapping;
|
|
32
|
-
/**
|
|
33
|
-
* Quantized dense vector field — wraps `denseVector()` with `int8_hnsw` index type.
|
|
34
|
-
*
|
|
35
|
-
* Quantizes float32 vectors to int8 at index time, saving ~75% memory.
|
|
36
|
-
* Recommended for vectors with dims >= 384. Original float vectors are retained
|
|
37
|
-
* in the index, enabling a two-phase search pattern:
|
|
38
|
-
*
|
|
39
|
-
* 1. Fast approximate search using quantized int8 vectors
|
|
40
|
-
* 2. Precise rescore of top-k results using retained float vectors
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* // Index mapping
|
|
44
|
-
* const schema = mappings({
|
|
45
|
-
* title: text(),
|
|
46
|
-
* embedding: quantizedDenseVector({ dims: 768, similarity: 'cosine' }),
|
|
47
|
-
* }, {
|
|
48
|
-
* _source: { excludes: ['embedding'] },
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* // Two-phase search: fast kNN + precise rescore
|
|
52
|
-
* const result = query(schema)
|
|
53
|
-
* .knn('embedding', queryVector, { k: 100, num_candidates: 200 })
|
|
54
|
-
* .rescore(
|
|
55
|
-
* (q) => q.scriptScore(
|
|
56
|
-
* (inner) => inner.matchAll(),
|
|
57
|
-
* { source: "cosineSimilarity(params.v, 'embedding') + 1.0", params: { v: queryVector } }
|
|
58
|
-
* ),
|
|
59
|
-
* 100
|
|
60
|
-
* )
|
|
61
|
-
* .build();
|
|
62
|
-
*/
|
|
63
|
-
export declare const quantizedDenseVector: (options?: DenseVectorFieldOptions) => DenseVectorFieldMapping;
|
|
64
|
-
/**
|
|
65
|
-
* Sparse vector field — stores token-weight pairs for sparse retrieval (e.g. ELSER/BM25-style models).
|
|
66
|
-
* Complement to `denseVector()`. Query with the `sparse_vector` query.
|
|
67
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sparse-vector.html
|
|
68
|
-
*/
|
|
69
|
-
export declare const sparseVector: () => SparseVectorFieldMapping;
|
|
70
|
-
/**
|
|
71
|
-
* Semantic text field (ES 9.x) — ML-powered text field for semantic and hybrid search.
|
|
72
|
-
* Automatically generates and stores embeddings at index time using the configured inference endpoint.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* const schema = mappings({
|
|
76
|
-
* title: text(),
|
|
77
|
-
* body: semanticText({ inference_id: 'my-elser-endpoint' }),
|
|
78
|
-
* });
|
|
79
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/semantic-text.html
|
|
80
|
-
*/
|
|
81
|
-
export declare const semanticText: (options?: SemanticTextFieldOptions) => SemanticTextFieldMapping;
|
|
82
|
-
/**
|
|
83
|
-
* Unsigned long field (ES 9.0+) — stores unsigned 64-bit integer values (0 to 2^64-1).
|
|
84
|
-
* Use when values exceed the `long` range.
|
|
85
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html
|
|
86
|
-
*/
|
|
87
|
-
export declare const unsignedLong: (options?: UnsignedLongFieldOptions) => UnsignedLongFieldMapping;
|
|
88
|
-
export declare const geoPoint: (options?: GeoPointFieldOptions) => GeoPointFieldMapping;
|
|
89
|
-
export declare const geoShape: (options?: GeoShapeFieldOptions) => GeoShapeFieldMapping;
|
|
90
|
-
export declare const completion: (options?: CompletionFieldOptions) => CompletionFieldMapping;
|
|
91
|
-
/**
|
|
92
|
-
* Object field — for JSON-like structured documents where sub-fields are queried with dot-notation.
|
|
93
|
-
*
|
|
94
|
-
* The most common way to model structured data (e.g. `{ address: { city, zip } }`).
|
|
95
|
-
* Sub-fields are indexed inline within the parent document — no special query wrapper needed.
|
|
96
|
-
* Query sub-fields directly using dot-notation: `.term('address.city', 'NYC')`.
|
|
97
|
-
*
|
|
98
|
-
* Use `nested()` instead when you have **arrays of objects** and need cross-field queries
|
|
99
|
-
* within each element to be accurate (e.g. tags with both a label and weight).
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* const m = mappings({
|
|
103
|
-
* address: object({
|
|
104
|
-
* street: text(),
|
|
105
|
-
* city: keyword(),
|
|
106
|
-
* zip: keyword(),
|
|
107
|
-
* }),
|
|
108
|
-
* });
|
|
109
|
-
* query(m).term('address.city', 'NYC').build();
|
|
110
|
-
*/
|
|
111
|
-
export declare function object<F extends Record<string, FieldMappingWithLiteralType>>(fields: F, options?: ObjectFieldOptions): TypedObjectFieldMapping<F>;
|
|
112
|
-
/**
|
|
113
|
-
* Nested field — for **arrays of objects** where cross-field queries within each element must be accurate.
|
|
114
|
-
*
|
|
115
|
-
* Each nested object is stored as a separate hidden Elasticsearch document, preserving the
|
|
116
|
-
* relationship between sub-fields within each element. Without `nested`, Elasticsearch flattens
|
|
117
|
-
* array sub-fields and loses which values belong to the same element.
|
|
118
|
-
*
|
|
119
|
-
* Queries on nested fields **must** use the `.nested()` query builder method — direct dot-notation
|
|
120
|
-
* queries will not find nested documents.
|
|
121
|
-
*
|
|
122
|
-
* Use `object()` instead for single structured objects (addresses, names, etc.) — it is simpler,
|
|
123
|
-
* more efficient, and does not require a query wrapper.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* const m = mappings({
|
|
127
|
-
* tags: nested({
|
|
128
|
-
* label: keyword(),
|
|
129
|
-
* weight: float(),
|
|
130
|
-
* }),
|
|
131
|
-
* });
|
|
132
|
-
* query(m).nested('tags', q => q.term('label', 'sale')).build();
|
|
133
|
-
*/
|
|
134
|
-
export declare function nested<F extends Record<string, FieldMappingWithLiteralType>>(fields: F): TypedNestedFieldMapping<F>;
|
|
135
|
-
export declare const alias: (options: AliasFieldOptions) => AliasFieldMapping;
|
|
136
|
-
export declare const percolator: () => PercolatorFieldMapping;
|
|
137
|
-
export declare const integerRange: (options?: RangeFieldOptions) => IntegerRangeFieldMapping;
|
|
138
|
-
export declare const floatRange: (options?: RangeFieldOptions) => FloatRangeFieldMapping;
|
|
139
|
-
export declare const longRange: (options?: RangeFieldOptions) => LongRangeFieldMapping;
|
|
140
|
-
export declare const doubleRange: (options?: RangeFieldOptions) => DoubleRangeFieldMapping;
|
|
141
|
-
export declare const dateRange: (options?: RangeFieldOptions) => DateRangeFieldMapping;
|
|
142
|
-
/**
|
|
143
|
-
* No-score text field — faster and uses less disk than `text()`.
|
|
144
|
-
* Use when you only need filter/match but not relevance scoring (e.g., logs, simple field matches).
|
|
145
|
-
*/
|
|
146
|
-
export declare const matchOnlyText: (options?: MatchOnlyTextFieldOptions) => MatchOnlyTextFieldMapping;
|
|
147
|
-
/**
|
|
148
|
-
* Autocomplete / typeahead field. Creates sub-fields for edge n-gram matching
|
|
149
|
-
* out of the box. Query with `multi_match` targeting the generated sub-fields.
|
|
150
|
-
*/
|
|
151
|
-
export declare const searchAsYouType: (options?: SearchAsYouTypeFieldOptions) => SearchAsYouTypeFieldMapping;
|
|
152
|
-
/**
|
|
153
|
-
* Field where every document has the same value. Useful for multi-index queries
|
|
154
|
-
* to identify the index type (e.g., `constantKeyword({ value: 'product' })`).
|
|
155
|
-
*/
|
|
156
|
-
export declare const constantKeyword: (options?: ConstantKeywordFieldOptions) => ConstantKeywordFieldMapping;
|
|
157
|
-
/**
|
|
158
|
-
* Optimized for grep-like wildcard/regexp queries on high-cardinality or large fields.
|
|
159
|
-
* Use instead of `keyword()` when leading wildcards (`*foo`) are needed.
|
|
160
|
-
*/
|
|
161
|
-
export declare const wildcardField: (options?: WildcardFieldOptions) => WildcardFieldMapping;
|
|
162
|
-
/**
|
|
163
|
-
* Flattens complex/dynamic objects into a single field. Faster than `nested()`,
|
|
164
|
-
* but only supports keyword-level queries on inner values.
|
|
165
|
-
*/
|
|
166
|
-
export declare const flattened: (options?: FlattenedFieldOptions) => FlattenedFieldMapping;
|
|
167
|
-
//# sourceMappingURL=field.helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC3B,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,eAAO,MAAM,IAAI,GAAI,UAAU,gBAAgB,KAAG,gBAGhD,CAAC;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,mBAAmB,K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,oBAAoB,KAAG,oBAG7D,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,qBAAqB,KAAG,qBAG1D,CAAC"}
|
package/dist/field.helpers.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Field type helper functions for ergonomic index mapping definitions.
|
|
3
|
-
* Each helper returns a narrowly-typed mapping with a literal `type` field,
|
|
4
|
-
* enabling compile-time field-type inference in the query builder.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { text, keyword, denseVector, mappings } from 'elasticlink';
|
|
8
|
-
*
|
|
9
|
-
* const productMappings = mappings({
|
|
10
|
-
* name: text({ analyzer: 'standard' }),
|
|
11
|
-
* price: float(),
|
|
12
|
-
* category: keyword(),
|
|
13
|
-
* embedding: denseVector({ dims: 384 }),
|
|
14
|
-
* });
|
|
15
|
-
*/
|
|
16
|
-
// Text & keyword
|
|
17
|
-
export const text = (options) => ({
|
|
18
|
-
type: 'text',
|
|
19
|
-
...options
|
|
20
|
-
});
|
|
21
|
-
export const keyword = (options) => ({
|
|
22
|
-
type: 'keyword',
|
|
23
|
-
...options
|
|
24
|
-
});
|
|
25
|
-
// Numeric
|
|
26
|
-
export const long = (options) => ({
|
|
27
|
-
type: 'long',
|
|
28
|
-
...options
|
|
29
|
-
});
|
|
30
|
-
export const integer = (options) => ({
|
|
31
|
-
type: 'integer',
|
|
32
|
-
...options
|
|
33
|
-
});
|
|
34
|
-
export const short = (options) => ({
|
|
35
|
-
type: 'short',
|
|
36
|
-
...options
|
|
37
|
-
});
|
|
38
|
-
export const byte = (options) => ({
|
|
39
|
-
type: 'byte',
|
|
40
|
-
...options
|
|
41
|
-
});
|
|
42
|
-
export const double = (options) => ({
|
|
43
|
-
type: 'double',
|
|
44
|
-
...options
|
|
45
|
-
});
|
|
46
|
-
export const float = (options) => ({
|
|
47
|
-
type: 'float',
|
|
48
|
-
...options
|
|
49
|
-
});
|
|
50
|
-
export const halfFloat = (options) => ({
|
|
51
|
-
type: 'half_float',
|
|
52
|
-
...options
|
|
53
|
-
});
|
|
54
|
-
export const scaledFloat = (options) => ({
|
|
55
|
-
type: 'scaled_float',
|
|
56
|
-
...options
|
|
57
|
-
});
|
|
58
|
-
// Date & boolean
|
|
59
|
-
export const date = (options) => ({
|
|
60
|
-
type: 'date',
|
|
61
|
-
...options
|
|
62
|
-
});
|
|
63
|
-
export const boolean = (options) => ({
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
...options
|
|
66
|
-
});
|
|
67
|
-
// Binary
|
|
68
|
-
// eslint-disable-next-line functional/functional-parameters
|
|
69
|
-
export const binary = () => ({ type: 'binary' });
|
|
70
|
-
// IP
|
|
71
|
-
export const ip = (options) => ({
|
|
72
|
-
type: 'ip',
|
|
73
|
-
...options
|
|
74
|
-
});
|
|
75
|
-
// Vector
|
|
76
|
-
export const denseVector = (options) => ({
|
|
77
|
-
type: 'dense_vector',
|
|
78
|
-
...options
|
|
79
|
-
});
|
|
80
|
-
/**
|
|
81
|
-
* Quantized dense vector field — wraps `denseVector()` with `int8_hnsw` index type.
|
|
82
|
-
*
|
|
83
|
-
* Quantizes float32 vectors to int8 at index time, saving ~75% memory.
|
|
84
|
-
* Recommended for vectors with dims >= 384. Original float vectors are retained
|
|
85
|
-
* in the index, enabling a two-phase search pattern:
|
|
86
|
-
*
|
|
87
|
-
* 1. Fast approximate search using quantized int8 vectors
|
|
88
|
-
* 2. Precise rescore of top-k results using retained float vectors
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* // Index mapping
|
|
92
|
-
* const schema = mappings({
|
|
93
|
-
* title: text(),
|
|
94
|
-
* embedding: quantizedDenseVector({ dims: 768, similarity: 'cosine' }),
|
|
95
|
-
* }, {
|
|
96
|
-
* _source: { excludes: ['embedding'] },
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* // Two-phase search: fast kNN + precise rescore
|
|
100
|
-
* const result = query(schema)
|
|
101
|
-
* .knn('embedding', queryVector, { k: 100, num_candidates: 200 })
|
|
102
|
-
* .rescore(
|
|
103
|
-
* (q) => q.scriptScore(
|
|
104
|
-
* (inner) => inner.matchAll(),
|
|
105
|
-
* { source: "cosineSimilarity(params.v, 'embedding') + 1.0", params: { v: queryVector } }
|
|
106
|
-
* ),
|
|
107
|
-
* 100
|
|
108
|
-
* )
|
|
109
|
-
* .build();
|
|
110
|
-
*/
|
|
111
|
-
export const quantizedDenseVector = (options) => ({
|
|
112
|
-
type: 'dense_vector',
|
|
113
|
-
...options,
|
|
114
|
-
index_options: { type: 'int8_hnsw', ...options?.index_options }
|
|
115
|
-
});
|
|
116
|
-
/**
|
|
117
|
-
* Sparse vector field — stores token-weight pairs for sparse retrieval (e.g. ELSER/BM25-style models).
|
|
118
|
-
* Complement to `denseVector()`. Query with the `sparse_vector` query.
|
|
119
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/sparse-vector.html
|
|
120
|
-
*/
|
|
121
|
-
// eslint-disable-next-line functional/functional-parameters
|
|
122
|
-
export const sparseVector = () => ({ type: 'sparse_vector' });
|
|
123
|
-
/**
|
|
124
|
-
* Semantic text field (ES 9.x) — ML-powered text field for semantic and hybrid search.
|
|
125
|
-
* Automatically generates and stores embeddings at index time using the configured inference endpoint.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* const schema = mappings({
|
|
129
|
-
* title: text(),
|
|
130
|
-
* body: semanticText({ inference_id: 'my-elser-endpoint' }),
|
|
131
|
-
* });
|
|
132
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/semantic-text.html
|
|
133
|
-
*/
|
|
134
|
-
export const semanticText = (options) => ({
|
|
135
|
-
type: 'semantic_text',
|
|
136
|
-
...options
|
|
137
|
-
});
|
|
138
|
-
/**
|
|
139
|
-
* Unsigned long field (ES 9.0+) — stores unsigned 64-bit integer values (0 to 2^64-1).
|
|
140
|
-
* Use when values exceed the `long` range.
|
|
141
|
-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html
|
|
142
|
-
*/
|
|
143
|
-
export const unsignedLong = (options) => ({
|
|
144
|
-
type: 'unsigned_long',
|
|
145
|
-
...options
|
|
146
|
-
});
|
|
147
|
-
// Geo
|
|
148
|
-
export const geoPoint = (options) => ({
|
|
149
|
-
type: 'geo_point',
|
|
150
|
-
...options
|
|
151
|
-
});
|
|
152
|
-
export const geoShape = (options) => ({
|
|
153
|
-
type: 'geo_shape',
|
|
154
|
-
...options
|
|
155
|
-
});
|
|
156
|
-
// Completion
|
|
157
|
-
export const completion = (options) => ({
|
|
158
|
-
type: 'completion',
|
|
159
|
-
...options
|
|
160
|
-
});
|
|
161
|
-
// Structured
|
|
162
|
-
/**
|
|
163
|
-
* Object field — for JSON-like structured documents where sub-fields are queried with dot-notation.
|
|
164
|
-
*
|
|
165
|
-
* The most common way to model structured data (e.g. `{ address: { city, zip } }`).
|
|
166
|
-
* Sub-fields are indexed inline within the parent document — no special query wrapper needed.
|
|
167
|
-
* Query sub-fields directly using dot-notation: `.term('address.city', 'NYC')`.
|
|
168
|
-
*
|
|
169
|
-
* Use `nested()` instead when you have **arrays of objects** and need cross-field queries
|
|
170
|
-
* within each element to be accurate (e.g. tags with both a label and weight).
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* const m = mappings({
|
|
174
|
-
* address: object({
|
|
175
|
-
* street: text(),
|
|
176
|
-
* city: keyword(),
|
|
177
|
-
* zip: keyword(),
|
|
178
|
-
* }),
|
|
179
|
-
* });
|
|
180
|
-
* query(m).term('address.city', 'NYC').build();
|
|
181
|
-
*/
|
|
182
|
-
export function object(fields, options) {
|
|
183
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
-
return { type: 'object', ...(options ?? {}), properties: fields };
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Nested field — for **arrays of objects** where cross-field queries within each element must be accurate.
|
|
188
|
-
*
|
|
189
|
-
* Each nested object is stored as a separate hidden Elasticsearch document, preserving the
|
|
190
|
-
* relationship between sub-fields within each element. Without `nested`, Elasticsearch flattens
|
|
191
|
-
* array sub-fields and loses which values belong to the same element.
|
|
192
|
-
*
|
|
193
|
-
* Queries on nested fields **must** use the `.nested()` query builder method — direct dot-notation
|
|
194
|
-
* queries will not find nested documents.
|
|
195
|
-
*
|
|
196
|
-
* Use `object()` instead for single structured objects (addresses, names, etc.) — it is simpler,
|
|
197
|
-
* more efficient, and does not require a query wrapper.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* const m = mappings({
|
|
201
|
-
* tags: nested({
|
|
202
|
-
* label: keyword(),
|
|
203
|
-
* weight: float(),
|
|
204
|
-
* }),
|
|
205
|
-
* });
|
|
206
|
-
* query(m).nested('tags', q => q.term('label', 'sale')).build();
|
|
207
|
-
*/
|
|
208
|
-
export function nested(fields) {
|
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
-
return { type: 'nested', properties: fields };
|
|
211
|
-
}
|
|
212
|
-
// Alias
|
|
213
|
-
export const alias = (options) => ({
|
|
214
|
-
type: 'alias',
|
|
215
|
-
...options
|
|
216
|
-
});
|
|
217
|
-
// Percolator
|
|
218
|
-
// eslint-disable-next-line functional/functional-parameters
|
|
219
|
-
export const percolator = () => ({
|
|
220
|
-
type: 'percolator'
|
|
221
|
-
});
|
|
222
|
-
// Range types
|
|
223
|
-
export const integerRange = (options) => ({
|
|
224
|
-
type: 'integer_range',
|
|
225
|
-
...options
|
|
226
|
-
});
|
|
227
|
-
export const floatRange = (options) => ({
|
|
228
|
-
type: 'float_range',
|
|
229
|
-
...options
|
|
230
|
-
});
|
|
231
|
-
export const longRange = (options) => ({
|
|
232
|
-
type: 'long_range',
|
|
233
|
-
...options
|
|
234
|
-
});
|
|
235
|
-
export const doubleRange = (options) => ({
|
|
236
|
-
type: 'double_range',
|
|
237
|
-
...options
|
|
238
|
-
});
|
|
239
|
-
export const dateRange = (options) => ({
|
|
240
|
-
type: 'date_range',
|
|
241
|
-
...options
|
|
242
|
-
});
|
|
243
|
-
/**
|
|
244
|
-
* No-score text field — faster and uses less disk than `text()`.
|
|
245
|
-
* Use when you only need filter/match but not relevance scoring (e.g., logs, simple field matches).
|
|
246
|
-
*/
|
|
247
|
-
export const matchOnlyText = (options) => ({
|
|
248
|
-
type: 'match_only_text',
|
|
249
|
-
...options
|
|
250
|
-
});
|
|
251
|
-
/**
|
|
252
|
-
* Autocomplete / typeahead field. Creates sub-fields for edge n-gram matching
|
|
253
|
-
* out of the box. Query with `multi_match` targeting the generated sub-fields.
|
|
254
|
-
*/
|
|
255
|
-
export const searchAsYouType = (options) => ({
|
|
256
|
-
type: 'search_as_you_type',
|
|
257
|
-
...options
|
|
258
|
-
});
|
|
259
|
-
/**
|
|
260
|
-
* Field where every document has the same value. Useful for multi-index queries
|
|
261
|
-
* to identify the index type (e.g., `constantKeyword({ value: 'product' })`).
|
|
262
|
-
*/
|
|
263
|
-
export const constantKeyword = (options) => ({
|
|
264
|
-
type: 'constant_keyword',
|
|
265
|
-
...options
|
|
266
|
-
});
|
|
267
|
-
/**
|
|
268
|
-
* Optimized for grep-like wildcard/regexp queries on high-cardinality or large fields.
|
|
269
|
-
* Use instead of `keyword()` when leading wildcards (`*foo`) are needed.
|
|
270
|
-
*/
|
|
271
|
-
export const wildcardField = (options) => ({
|
|
272
|
-
type: 'wildcard',
|
|
273
|
-
...options
|
|
274
|
-
});
|
|
275
|
-
/**
|
|
276
|
-
* Flattens complex/dynamic objects into a single field. Faster than `nested()`,
|
|
277
|
-
* but only supports keyword-level queries on inner values.
|
|
278
|
-
*/
|
|
279
|
-
export const flattened = (options) => ({
|
|
280
|
-
type: 'flattened',
|
|
281
|
-
...options
|
|
282
|
-
});
|