OSx
1. elasticsearch
brew elasticsearch//
elasticsearch//
2.
2.1 ES
- npm install elasticsearch --save
2.2
FOLDER : routers/elastic-search-router.js
var express= require('express');
var router= express.Router();
var elasticsearch=require('elasticsearch');
var client = new elasticsearch.Client( {
hosts: [
'http://localhost:9200/',
]
});
router.get('/health',function(req,res){
client.cluster.health({},function(err,resp,status) {
if(err)
{ console.log("-- Client Health ERROR--",err);
}else{
console.log("-- Client Health --",resp);
res.send({resp});
}
});
});
router.get('/createIndex',function(req,res){
client.indices.create({
index: 'imageMap'
},function(err,resp,status) {
if(err) {
console.log(err);
}
else {
console.log("create",resp);
res.send({resp});
}
});
});
module.exports =router;
2.2 Now inside the Express index.js file
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var path= require('path');
app.use(require(path.join(__dirname,'routers/elastic-search-router')));
....
2.3 Launch Express Server:
IN TERMINAL : node index.js
In the application url, you can access each function in ur router as:
http: // localhost: 3000 / createIndex
http: // localhost: 3000 / health
source
share