mongo2elastic
Version:
Sync MongoDB collections to Elasticsearch
46 lines (45 loc) • 1.9 kB
TypeScript
import { estypes } from '@elastic/elasticsearch';
import makeError from 'make-error';
import { type JSONSchema } from 'mongochangestream';
import { ConvertOptions } from './types.js';
export declare const Mongo2ElasticError: makeError.Constructor<makeError.BaseError>;
/**
* Convert MongoDB JSON schema to Elasticsearch mapping.
*
* There are options that allow you to preprocess nodes, omit fields, rename
* fields, and change the BSON type for fields (e.g. when a more specific
* numeric type is needed).
* @see {@link ConvertOptions} for details.
*/
export declare const convertSchema: (jsonSchema: JSONSchema, options?: ConvertOptions) => estypes.MappingPropertyBase;
/**
* Helper function to manually set the Elasticsearch type for a given path.
* Only applicable for scalar types.
* @example
* setESType('latlong', 'geo_point')
*/
export declare const setESType: (path: string, type: string) => {
path: string;
mapper: ({ bsonType, ...rest }: JSONSchema) => {
type: string;
};
};
/**
* Generate an override for all fields that match the provided `path` pattern
* and (optional) `condition`, adding the provided `groupField` to the
* `copy_to` array. Ensures that any existing `copy_to` values are preserved.
*
* @param path - the path pattern to match
* @param groupField - the group field(s) to add to this mapping's `copy_to` array
* @param [predicate] - an optional function that must return true in order for
* the override to be applicable to this mapping
*/
export declare const copyTo: (path: string, groupField: string | string[], predicate?: (obj: JSONSchema) => boolean) => {
path: string;
mapper: (obj: JSONSchema) => JSONSchema;
};
/**
* Helper function to determine if a field is stringlike.
* @returns true if the field is a string or an array of strings
*/
export declare const isStringlike: (obj: JSONSchema) => boolean;