我在尝试在node.js中实现Elasticsearch时收到以下错误消息。我已经尝试了各种解决方案提供类似的问题,但它仍然显示相同的错误信息。
类似问题(How can I fix error: ConfigurationError: Missing node(s) option for winston-elasticsearch?)
另外,我使用下面的npm包来实现elasticSearch:https://www.npmjs.com/package/@elastic/elasticsearch
如果有人能帮我解决这个问题。
如果你需要我提供更多的信息请告诉我。
请在下面找到相关代码。
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;
1条答案
按热度按时间3htmauhk1#
我想因为这条线
也许你的弹性客户端无法访问这个主机尝试与
https://localhost:9200