'Missing node(s) option error while trying to implement elasticSearch in node.js

I am getting the below error message while trying to implement Elasticsearch in node.js. I have tried various solutions provided to similar problem but its still showing the same error message.

Similar problem (How can I fix error: ConfigurationError: Missing node(s) option for winston-elasticsearch?)

Additionally I am using the below npm package to implement elasticSearch: https://www.npmjs.com/package/@elastic/elasticsearch

If someone can please help me resolve this issue.

Let me know if you require any further information from my end.

Please find below relevant codes.

router.js

const express = require('express');
const router = new express.Router();
const elastic = require('@elastic/elasticsearch');
const bodyParser = require('body-parser').json();
//const userSearch = require('../models/search');
const multer = require('multer');
var fs = require('fs');
 var path = require('path');
var JSONStream = require('JSONStream');
//const elastic = require('mongoose-elasticsearch-xp');
const UserSearch = require('../models/search');


let productos = [
 {   
"sku": "1",
"name" : "Sillón 3 cuerpos",
"categories": ["sillon",
"sofa", "muebles", "living", "cuero"],
"description": "Hermoso sillón de cuero de 3 cuerpos"
 },

{
"sku": "2",
"name": "Sillón 2 cuerpos",
"categories": ["sillon",
"sofa", "muebles", "living", "ecocuero"],
"description": "Hermoso sillón de ecocuero de 2 cuerpos"
},
{
"sku": "3",
"name": "Mesa de comedor redonda de vidrio",
"categories": ["mesa", "comedor", "vidrio"],
"description": "Moderna mesa de 110 cm de radio"
}
];



const elasticClient = new elastic.Client({
    host : 'localhost:9200',
});

router.use((req, res, next)=>{
    elasticClient.index({
    index:'logs',
    body:{
    url: req.url,
    method: req.method,
    }
})
    .then(res=>{
    console. log ('Logs indexed')
    })
    .catch(err=>{
    console. log(err)
    });
    next();
});


router.get('/products', (reg, res)=>{
    let query = {
    index: 'products'
    }
    if (req.query.product) query.q = "*${req.query.product)*";
    elasticClient.search(query)
    .then (resp=>{
    return res.status (200). json({
    products: resp.hits.hits
    })
    .catch(err=>{
    console. log(err);
    return res.status (500). json({
    msg: 'Error',
    err
    });
});
    });
});
    module. exports = router;



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source