File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
p2-integrate-elasticsearch-with-node Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ const elasticsearch = require ( 'elasticsearch' ) ;
2
+ const indexName = 'demo_elastic_index' ;
3
+ const deleteIndex = async ( ) => {
4
+ const client = new elasticsearch . Client ( {
5
+ host : 'localhost:9200' ,
6
+ // log: 'trace',
7
+ } ) ;
8
+ await client . ping ( {
9
+ requestTimeout : 3000
10
+ } , function ( error ) {
11
+ if ( error ) {
12
+ console . trace ( 'elasticsearch cluster is down!' ) ;
13
+ } else {
14
+ console . log ( 'Elastic search is running.' ) ;
15
+ }
16
+ } ) ;
17
+ try {
18
+ await client . indices . delete ( { index : indexName } ) ;
19
+ console . log ( 'All index is deleted' ) ;
20
+ } catch ( e ) {
21
+ // console.log("Error in deleteing index",e);
22
+ if ( e . status === 404 ) {
23
+ console . log ( 'Index Not Found' ) ;
24
+ } else {
25
+ throw e ;
26
+ }
27
+ }
28
+ }
29
+ deleteIndex ( ) ;
You can’t perform that action at this time.
0 commit comments