0
我想在nodejs中使用elasticsearch的官方客戶端來爲chouchDB創建索引。真的很感激任何幫助。使用elasticssearch客戶端創建索引
這是我正在創建一個索引:
esClient.indices.create({index: "users_index",
body: {
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" :"5984",
"db" :"users"
},
"index" : {
"index" : "users_index",
"type" : "users",
"bulk_size" : "100",
"bulk_timeout" : "10ms"
}
}}).then(function(x){
console.log(x);
callback(null);
},
function(err){
console.log(err);
callback(null);
});
當我搜索這樣的檢測數據(GET users_index/users_index/_search),我得到這個沒有任何數據: { 「了「:1, 「TIMED_OUT」:假的, 「_shards」:{ 「總」:1, 「成功」:1, 「失敗」:0 }, 「命中」:{ 「總」 :0, 「max_score」:null, 「hits」:[] } }
我真的很感謝任何幫助。
在創建索引之前,我也嘗試創建一個索引模板,以便我的所有索引都獲得相同的映射。我像下面這樣做。我還沒有走過那麼遠去驗證它是否正確。請讓我知道這是否有任何錯誤。
esClient.indices.putTemplate({
name: "vw_index_template",
body:{
"template" : "*_index",
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"id_prkey_template" : {
"properties" : {
"_id" : {"type" : "string", "index": "not_analyzed"},
"prkey" : {"type" : "string", "index": "analyzed"}
}
}
}
}
}).then(function(res){
console.log(res);
callback(null);
}, function(error){
console.log(error);
callback(null);
});
真的很感激任何幫助。
非常感謝。
我試過你的建議,但似乎不工作。我想要做的是創建一個從couchdb導入數據的索引(我正在使用coucdb river插件進行elasticsearch)。 – Imad
我嘗試了下面的代碼來完成我在上面評論中所說的內容。 'curl -XPUT「http:// localhost:9200/_river/user_idx/_meta」-d「{type:」couchdb「,」couchdb「:{」host「:」localhost「,」port「 5984,「db」:「users」,「filter」:null}, \t「index」:{「index」:「user_idx」,「type」:「users」,「bulk_size」:「100」,「bulk_timeout 「:」10ms「}}」',它工作正常。現在試圖在elasticsearchclient的nodejs中做同樣的事情。我嘗試了你的建議,但似乎沒有做我想要的。 – Imad
關於你對不使用_id進行映射的建議,你能告訴我如何讓我的couchdb數據庫的_id可以被搜索,即如何在索引中添加它?謝謝。 – Imad