使用带有节点js的Typescript从弹性搜索中删除记录 [英] delete record from elastic search using typescript with node js
本文介绍了使用带有节点js的Typescript从弹性搜索中删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是弹性搜索的新手.我正在使用7.4.0版弹性搜索.我可以使用@ elastic/elasticsearch npm包在弹性搜索中创建和更新记录.我正在将Node js与Typescript一起使用.当我尝试从弹性搜索中删除记录时,它给了我"Response Error".我没有明白这里出了什么问题.下面是我的代码.
I am new to elastic search. I am using elastic search version 7.4.0. I am able to create and update record in elastic search by using @elastic/elasticsearch npm package. I am using node js with typescript. When I am trying to delete record from elastic search it is giving me "Response Error". I am not getting what is wrong here. Below is my code.
import { Client, ApiResponse, RequestParams } from "@elastic/elasticsearch";
export class ElasticSearchService {
public async deleteIndex (index: string, id: string): Promise<any> {
return new Promise<any>(async (resolve: any, reject: any) => {
try {
const doc1: RequestParams.Delete = {
index: index,
id: id
};
let result: ApiResponse = await client.delete(doc1);
resolve(result);
} catch (e) {
reject(e);
}
});
}
}
推荐答案
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });
export class ElsastricSearch {
deleteData = async (index: string, type: string, id: string ) => {
return new Promise<any>(async (resolve, reject) => {
try {
let result = await client.delete({
index: index,
type: type,
id: id,
});
resolve(result);
} catch (error) {
reject(error);
}
});
};
}
我已经测试了typeScript,并且可以正常工作
I have tested typeScript and it's working fine
这篇关于使用带有节点js的Typescript从弹性搜索中删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文