Skip to content

Commit 24d384b

Browse files
committed
fix: delete by query
1 parent eb1244d commit 24d384b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/__tests__/elastic-client.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ElasticClient } from '../elastic-client'
22
import 'isomorphic-fetch'
3+
34
describe('elastic-client', () => {
45
it('should create and delete elastic index', async () => {
56
const client = new ElasticClient({ hosts: ['http://localhost:9200'] })
@@ -129,6 +130,37 @@ describe('elastic-client', () => {
129130
expect(result.code).toBe(200)
130131
})
131132

133+
it('should delete document', async () => {
134+
const client = new ElasticClient({ hosts: ['http://localhost:9200'] })
135+
136+
await client.index({
137+
index: 'hello-world2',
138+
document: { hello: true },
139+
id: '21',
140+
})
141+
142+
await client.refreshIndex({ index: 'hello-world2' })
143+
await client.deleteByQuery({
144+
index: 'hello-world2',
145+
query: {
146+
match: {
147+
hello: true,
148+
},
149+
},
150+
})
151+
await client.refreshIndex({ index: 'hello-world2' })
152+
const search = await client.search({
153+
index: 'hello-world2',
154+
query: {
155+
match: {
156+
hello: true,
157+
},
158+
},
159+
})
160+
161+
expect(search.data.hits.hits.length).toBe(0)
162+
})
163+
132164
it('should bulk index', async () => {
133165
const client = new ElasticClient({ hosts: ['http://localhost:9200'] })
134166
const result = await client.bulk({

src/elastic-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class ElasticClient {
333333
}
334334

335335
async deleteByQuery(params: DeleteByQueryRequest): Promise<Response<DeleteByQueryResponse>> {
336-
let url = `/${params.index}_delete_by_query`
336+
let url = `/${params.index}/_delete_by_query`
337337

338338
const queryParams = queryParametersGenerator(
339339
{

0 commit comments

Comments
 (0)