使用elasticssearch客户端创建索引 [英] using elasticssearch client to create indices
问题描述
我正在尝试在nodejs中使用elasticsearch的官方客户端来为chouchDB创建索引。真的很感激任何帮助。
I am trying to use elasticsearch's official client in nodejs to create indices for chouchDB. Will really appreciate any help.
这就是我创建索引的方式:
This is how I am creating an index:
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),我得到了这个没有任何数据:
{
take:1,
timed_out:false,
_shards:{
total:1,
成功:1,
失败:0
},
点击:{
总计:0,
max_score: null,
点击:[]
}
}
When I search for data like this in sense (GET users_index/users_index/_search), I get this without any data: { "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 0, "max_score": null, "hits": [] } }
我真的很感激任何帮助。
I'll really appreciate any help.
在创建索引之前,我还尝试创建索引模板,以便我的所有索引都获得相同的映射。我这样做就像以下一样。我没有走那么远来验证它是否正确。如果有任何错误,请告诉我。
Before creating index, I am also trying to create an index template so that all my indices get the same mapping. I am doing it like following. I have not gone that far to verify if its correct. Please let me know if there are any errors in this.
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);
});
非常感谢任何帮助。
非常感谢。
推荐答案
您无法将文档(正文)附加到 indices.create
(见这里)。如果您只想将新文档索引到现有或不存在的索引中,则应使用 index
,例如:
You can't attach a document (body) to indices.create
(see here). If you want to simply index new documents into a either existing or non-existing index you should use index
, for example:
esClient.index({
index: "users_index",
type: "couchdb",
body: {
field1: 'test',
field2: 123
}
}).then(function (x) {
console.log(x);
callback(null);
},
function (err) {
console.log(err);
callback(null);
});
此外,您不应为 _id $指定任何映射c $ c>字段,因为它是一个内部ES字段。
Also, you shouldn't specify any mapping for the _id
field since it's an internal ES field.
这篇关于使用elasticssearch客户端创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!