import { BaseController } from "./Base"; import { JSONObject, mCreateResponse, ArgsDefault, mCreateRequest, mCreateOrReplaceRequest, mCreateOrReplaceResponse, mDeleteRequest, mDeleteResponse, mReplaceRequest, mReplaceResponse, mUpdateRequest, mUpdateResponse, KDocumentContentGeneric, KDocument, KHit, mUpsertRequest } from "../types"; import { SearchResult } from "../core/searchResult/SearchResultBase"; export declare class DocumentController extends BaseController { constructor(kuzzle: any); /** * Counts documents in a collection. * * A query can be provided to alter the count result, * otherwise returns the total number of documents in the collection. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/count/ * * @param index Index name * @param collection Collection name * @param query Query to match * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The number of matching documents */ count(index: string, collection: string, body?: JSONObject, options?: ArgsDocumentControllerCount): Promise; /** * Creates a new document in the persistent data storage. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/create/ * * @param index Index name * @param collection Collection name * @param content Document content * @param _id Optional document ID * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The created document */ create(index: string, collection: string, content: Partial, _id?: string, options?: ArgsDocumentControllerCreate): Promise>; /** * Creates a new document in the persistent data storage, * or replaces its content if it already exists. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/create-or-replace/ * * @param index Index name * @param collection Collection name * @param id Document ID * @param content Document content * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The created or replaced document */ createOrReplace(index: string, collection: string, _id: string, content: Partial, options?: ArgsDocumentControllerCreateOrReplace): Promise>; /** * Deletes a document. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/delete/ * * @param index Index name * @param collection Collection name * @param _id Document ID * @param options Additional options * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The document ID */ delete(index: string, collection: string, _id: string, options?: ArgsDocumentControllerDelete): Promise; /** * Deletes documents matching the provided search query. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/delete-by-query/ * * @param index Index name * @param collection Collection name * @param query Query to match * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `lang` Query syntax. Can be 'elasticsearch' or 'koncorde' * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The deleted documents IDs */ deleteByQuery(index: string, collection: string, query?: JSONObject, options?: ArgsDocumentControllerDeleteByQuery): Promise; /** * Deletes fields of an existing document. * * @see https://docs.kuzzle.io/core/2/api/controllers/document/delete-fields/ * * @param index Index name * @param collection Collection name * @param _id Document ID * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `source` If true, the response will contain the updated document * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The updated document */ deleteFields(index: string, collection: string, _id: string, fields: string[], options?: ArgsDocumentControllerDeleteFields): Promise>; /** * Checks if the given document exists. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/exists/ * * @param index Index name * @param collection Collection name * @param _id Document ID * @param options Additional options * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns True if the document exists */ exists(index: string, collection: string, _id: string, options?: ArgsDocumentControllerExists): Promise; /** * Gets a document. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/get/ * * @param index Index name * @param collection Collection name * @param _id Document ID * @param options Additional options * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The document */ get(index: string, collection: string, _id: string, options?: ArgsDocumentControllerGet): Promise>; /** * Creates multiple documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-create/ * * @param index Index name * @param collection Collection name * @param documents Documents to create * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * - `strict` If true, an error will occur if a document was not created * * @returns An object containing 2 arrays: "successes" and "errors" */ mCreate(index: string, collection: string, documents: mCreateRequest, options?: ArgsDocumentControllerMCreate): Promise; /** * Creates or replaces multiple documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-create-or-replace/ * * @param index Index name * @param collection Collection name * @param documents Documents to create * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * - `strict` If true, an error will occur if a document was not created * * @returns An object containing 2 arrays: "successes" and "errors" */ mCreateOrReplace(index: string, collection: string, documents: mCreateOrReplaceRequest, options?: ArgsDocumentControllerMCreateOrReplace): Promise; /** * Deletes multiple documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-delete/ * * @param index Index name * @param collection Collection name * @param ids Document IDs * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * - `strict` If true, an error will occur if a document was not deleted * * @returns An object containing 2 arrays: "successes" and "errors" */ mDelete(index: string, collection: string, ids: mDeleteRequest, options?: ArgsDocumentControllerMDelete): Promise; /** * Gets multiple documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-get/ * * @param index Index name * @param collection Collection name * @param ids Document IDs * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `verb` (HTTP only) Forces the verb of the route * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns An object containing 2 arrays: "successes" and "errors" */ mGet(index: string, collection: string, ids: string[], options?: ArgsDocumentControllerMGet): Promise<{ /** * Array of successfully retrieved documents */ successes: KDocument[]; /** * Array of the IDs of not found documents. */ errors: string[]; }>; /** * Replaces multiple documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-replace/ * * @param index Index name * @param collection Collection name * @param documents Documents to create * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * - `strict` If true, an error will occur if a document was not replaced * * @returns An object containing 2 arrays: "successes" and "errors" */ mReplace(index: string, collection: string, documents: mReplaceRequest, options?: ArgsDocumentControllerMReplace): Promise; /** * Updates multiple documents. * * Conflicts may occur if the same document gets updated multiple times * within a short timespan in a database cluster. (See `retryOnConflict`) * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-update/ * * @param index Index name * @param collection Collection name * @param documents Documents to create * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `retryOnConflict` Number of times the database layer should retry in case of version conflict * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * - `strict` If true, an error will occur if a document was not updated * * @returns An object containing 2 arrays: "successes" and "errors" */ mUpdate(index: string, collection: string, documents: mUpdateRequest, options?: ArgsDocumentControllerMUpdate): Promise; /** * Applies partial updates to multiple documents. * * If a document doesn't already exist, a new document is created. * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/m-upsert/ * * @param index Index name * @param collection Collection name * @param documents Documents to update * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `retryOnConflict` Number of times the database layer should retry in case of version conflict * - `strict` If true, an error will occur if a document was not updated * * @returns An object containing 2 arrays: "successes" and "errors" */ mUpsert(index: string, collection: string, documents: mUpsertRequest, options?: ArgsDocumentControllerMUpsert): Promise; /** * Replaces the content of an existing document. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/replace/ * * @param index Index name * @param collection Collection name * @param id Document ID * @param content Document content * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The replaced document */ replace(index: string, collection: string, _id: string, content: Partial, options?: ArgsDocumentControllerReplace): Promise>; /** * Searches documents. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/search/ * * @param index Index name * @param collection Collection name * @param searchBody Search query * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `from` Offset of the first document to fetch * - `size` Maximum number of documents to retrieve per page * - `scroll` When set, gets a forward-only cursor having its ttl set to the given value (e.g. `30s`) * - `verb` (HTTP only) Forces the verb of the route * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns A SearchResult */ search(index: string, collection: string, searchBody?: JSONObject, options?: ArgsDocumentControllerSearch): Promise>>; private _search; /** * Updates the content of an existing document. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/update/ * * @param index Index name * @param collection Collection name * @param id Document ID * @param content Document content * @param options.queuable If true, queues the request during downtime, until connected to Kuzzle again * @param options.refresh If set to `wait_for`, Kuzzle will not respond until the API key is indexed * @param options.silent If true, then Kuzzle will not generate notifications * @param options.retryOnConflict Number of times the database layer should retry in case of version conflict * @param options.source If true, returns the updated document inside the response * @param options.timeout Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns The replaced document */ update(index: string, collection: string, _id: string, content: Partial, options?: ArgsDocumentControllerUpdate): Promise>; /** * Updates documents matching the provided search query. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/update-by-query/ * * @param index Index name * @param collection Collection name * @param query Query to match * @param changes Partial changes to apply to the documents * @param options Additional options * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `source` If true, returns the updated document inside the response * - `lang` Query syntax. Can be 'elasticsearch' or 'koncorde' * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns An object containing 2 arrays: "successes" and "errors" */ updateByQuery(index: string, collection: string, query: JSONObject, changes: Partial, options?: ArgsDocumentControllerUpdateByQuery): Promise>; /** * Applies a partial update to an existing document. * If the document doesn't already exist, a new document is created. * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/upsert/ * * @param index Index name * @param collection Collection name * @param _id Unique document identifier * @param changes Partial content of the document to update * @param [options] * - `default` Fields to add to the document if it gets created * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `retryOnConflict` Number of times the database layer should retry in case of version conflict * - `source` If true, returns the updated document inside the response * * @returns Information about the updated document */ upsert(index: string, collection: string, _id: string, changes: Partial, options?: ArgsDocumentControllerUpsert): Promise>; /** * Validates a document against existing validation rules. * * @see https://docs.kuzzle.io/sdk/js/7/controllers/document/validate/ * * @param index Index name * @param collection Collection name * @param content Document content * @param options Additional options * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `timeout` Request Timeout in ms, after the delay if not resolved the promise will be rejected * * @returns True if the document is valid */ validate(index: string, collection: string, content: TKDocumentContent, options?: ArgsDocumentControllerValidate): Promise; } export type ArgsDocumentControllerCount = ArgsDefault; export interface ArgsDocumentControllerCreate extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerCreateOrReplace extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerDelete extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerDeleteByQuery extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; lang?: string; } export interface ArgsDocumentControllerDeleteFields extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; source?: boolean; } export interface ArgsDocumentControllerExists extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerGet extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerMCreate extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; strict?: boolean; } export interface ArgsDocumentControllerMCreateOrReplace extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; strict?: boolean; } export interface ArgsDocumentControllerMDelete extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; strict?: boolean; } export interface ArgsDocumentControllerMGet extends ArgsDefault { verb?: string; } export interface ArgsDocumentControllerMReplace extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; strict?: boolean; } export interface ArgsDocumentControllerMUpdate extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; retryOnConflict?: number; strict?: boolean; } export interface ArgsDocumentControllerMUpsert extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; retryOnConflict?: number; strict?: boolean; } export interface ArgsDocumentControllerReplace extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; } export interface ArgsDocumentControllerSearch extends ArgsDefault { from?: number; size?: number; scroll?: string; lang?: string; verb?: string; } export interface ArgsDocumentControllerUpdate extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; retryOnConflict?: number; source?: boolean; } export interface ArgsDocumentControllerUpdateByQuery extends ArgsDefault { refresh?: "wait_for" | "false"; silent?: boolean; source?: boolean; lang?: string; } export interface ArgsDocumentControllerUpsert extends ArgsDefault { default?: Partial; refresh?: "wait_for" | "false"; silent?: boolean; retryOnConflict?: number; source?: boolean; } export type ArgsDocumentControllerValidate = ArgsDefault; export interface UpdateByQueryResponse { /** * Array of successfully updated documents */ successes: KDocument[]; /** * Array of failed creation */ errors: Array<{ /** * Document that cause the error */ document: KDocument; /** * HTTP error status */ status: number; /** * Human readable reason */ reason: string; }>; }