Skip to content

Commit

Permalink
feat(delete): 根据条件删除
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawei397 committed Jun 19, 2021
1 parent 078d637 commit 206b6a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
47 changes: 30 additions & 17 deletions examples/conn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Client } from "../mod.ts";
import { v4 } from "https://deno.land/[email protected]/uuid/mod.ts";
import mockjs from "https://deno.land/x/[email protected]/mod.ts";

const client = new Client();
await client.connect("http://localhost:9200/");
Expand All @@ -19,24 +20,15 @@ const count = async () => {
const create = async () => {
try {
const id = v4.generate();
const names = await client.create({
const info = await client.create({
index: "myindex2",
id,
data: {
deleted: false,
// _id: '6058046316761d2e8752aa4c44',
_name: "hahs",
title: "倚天屠龙记4",
content: "剑心通明4",
userId: "41",
isSecret: false,
group: "中国",
contentText: "剑心通明4",
titleText: "倚天屠龙记4",
id: "6058046316761d2e8752aa4c",
},
data: mockjs.mock({
"email": "@EMAIL",
"name": "@NAME",
}),
});
console.log(names);
console.log(info);
} catch (error) {
console.error(error);
}
Expand Down Expand Up @@ -77,13 +69,34 @@ const deleteById = async () => {
}
};

const deleteByQuery = async () => {
try {
const info = await client.deleteByQuery({
index: "myindex2",
data: {
query: {
"bool": {
"must": [{
"query_string": { "default_field": "email", "query": "@EMAIL" },
}],
},
},
},
});
console.log(info);
} catch (error) {
console.error(error);
}
};

console.time("ajax");
// await Array.from(new Array(100)).map(ajax);
// await create();
await create();
// await count();
// await update();

await deleteById();
// await deleteById();
// await deleteByQuery();

// setTimeout(async () => {
// await create();
Expand Down
16 changes: 16 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ export class Client {
});
}

deleteByQuery(params: {
index: string;
data: any;
}) {
const {
index,
data,
} = params;
const path = "/" + encodeURIComponent(index) + "/" + "_delete_by_query";
return ajax({
url: path,
method: "POST",
data,
});
}

close() {
if (this.conn) {
this.conn.close();
Expand Down

0 comments on commit 206b6a1

Please sign in to comment.