我想构建一个应用程序和一个将主要检索资源的api,现在我已经听说了很多Nodejs
,ElasticSearch
并且我对Nodejs和Express框架知之甚少。但是我不知道如何将ElasticSearch与Express框架集成在一起。
npm install elasticsearch --save
要使用该模块,只需创建一个客户端实例
var elasticsearch = require('elasticsearch');
var client = elasticsearch.Client({
host: 'localhost:9200'
});
client.search({
index: 'books',
type: 'book',
body: {
query: {
multi_match: {
query: 'express js',
fields: ['title', 'description']
}
}
}
}).then(function(response) {
var hits = response.hits.hits;
}).catch(function (error) {
console.trace(error.message);
});
有用的链接https://blog.raananweber.com/2015/11/24/simple-autocomplete-with-elasticsearch-and-node-js/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句