1

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);
            }
        });
    }
}

2 Answers 2

1
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);
            }
        });
    };

}

I have tested typeScript and it's working fine

Sign up to request clarification or add additional context in comments.

Comments

0
const data: RequestParams.Delete = {
            index: <<IndexName>>,
            id: <<ElasticId>>,
        }
        await client.delete(data);

1 Comment

Consider explaining the root cause of the problem and the solution. It'll improve both the OP and you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.