Skip to content

Commit

Permalink
feat(delete): query doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawei397 committed Jul 8, 2021
1 parent baf90b1 commit be5b025
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
.idea/
.DS_Store
.vscode/

.vercel
22 changes: 18 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CountInfo,
CreatedInfo,
DeleteByQueryInfo,
DeleteByQueryParams,
DeletedInfo,
DeleteIndexInfo,
DeleteParams,
Expand Down Expand Up @@ -178,20 +179,33 @@ export class Client extends BaseClient {
});
}

deleteByQuery(params: {
index: string;
body: any;
}): Promise<DeleteByQueryInfo> {
/**
* 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<DeleteByQueryInfo> {
assert(this.conn);
const {
index,
body,
timeout,
...otherParams
} = params;
const path = "/" + encodeURIComponent(index) + "/" + "_delete_by_query";
return ajax<DeleteByQueryInfo>({
url: path,
method: "POST",
data: body,
timeout,
query: otherParams,
});
}

Expand Down
40 changes: 40 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDeleteByQueryParams>;

0 comments on commit be5b025

Please sign in to comment.