nodejs elasticsearch基础使用,
/*链接到elasticsearch数据库*/
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.index({
index: 'myindex', //相当于database
type: 'mytype2', //相当于table
id: JSON.stringify(new Date().getTime()),// 数据到唯一标示,id存在则为更新,不存在为插入
body: {
title: 'Test 1',
tags: ['y', 'z'],
published: true,
published_at: '2013-01-01',
counter: 1,
name: '999'
}//文档到内容
}, (error, response)=>{
//
console.log(error)
console.log(response)
});
删除数据:
client.delete({
index: 'myindex',
type: 'mytype',
id: '3'
}, (error, response)=>{
// ...删除id为3的数据
});
查询数据:
client.search({
index: 'myindex',
type:'mytype',
body:{
query:{
// match:{
// name:'yyk'
// }
"terms" :{
"_id" : ["6"]
}
}
}
}, function (error, response) {
// ...
response.hits.hits.map((v)=>console.log(v))
});
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。