From be5b025fd77f4f8fe9153875213fb05143399674 Mon Sep 17 00:00:00 2001 From: jia wei Date: Thu, 8 Jul 2021 12:55:23 +0800 Subject: [PATCH] feat(delete): query doc --- .gitignore | 2 ++ src/client.ts | 22 ++++++++++++++++++---- src/types.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c819e36..d57272a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ .idea/ .DS_Store .vscode/ + +.vercel diff --git a/src/client.ts b/src/client.ts index f7c70eb..37db4e0 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,6 +6,7 @@ import { CountInfo, CreatedInfo, DeleteByQueryInfo, + DeleteByQueryParams, DeletedInfo, DeleteIndexInfo, DeleteParams, @@ -178,20 +179,33 @@ export class Client extends BaseClient { }); } - deleteByQuery(params: { - index: string; - body: any; - }): Promise { + /** + * Deletes documents that match the specified query. + * @example + * { + * "query": { + * "match": { + * "user.id": "elkbee" + * } + * } + * } + * @see {@link https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/7.x/api-reference.html#_deletebyquery} + */ + deleteByQuery(params: DeleteByQueryParams): Promise { assert(this.conn); const { index, body, + timeout, + ...otherParams } = params; const path = "/" + encodeURIComponent(index) + "/" + "_delete_by_query"; return ajax({ url: path, method: "POST", data: body, + timeout, + query: otherParams, }); } diff --git a/src/types.ts b/src/types.ts index 0922083..21c574a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -200,3 +200,43 @@ export interface DeleteParams { version?: number; version_type?: "internal" | "external" | "external_gte" | "force"; } + +interface IDeleteByQueryParams { + analyzer: string; + analyze_wildcard: boolean; + default_operator: "AND" | "OR"; + df: string; + from: number; + ignore_unavailable: boolean; + allow_no_indices: boolean; + conflicts: "abort" | "proceed"; + expand_wildcards: "open" | "closed" | "hidden" | "none" | "all"; + lenient: boolean; + preference: string; + q: string; + routing: string | string[]; + scroll: string; + search_type: "query_then_fetch" | "dfs_query_then_fetch"; + search_timeout: string; + size: number; + max_docs: number; + sort: string | string[]; + _source: string | string[]; + _source_excludes: string | string[]; + _source_includes: string | string[]; + terminate_after: number; + stats: string | string[]; + version: boolean; + request_cache: boolean; + refresh: boolean; + timeout: num; + wait_for_active_shards: string; + scroll_size: number; + wait_for_completion: boolean; + requests_per_second: number; + slices: number | string; +} +export type DeleteByQueryParams = { + index: string | string[]; + body: object; +} & Partial;