我正在尝试使用官方 javascript 客户端创建带有映射的 elasticsearch 索引。
我的代码如下:
client.indices.create({
index: "aName",
"mappings": {
"aType": {
"properties": {
"aProp1": { "type": "string", "index": "not_analyzed" },
"aProp2": { "type": "string", "index": "not_analyzed" },
"aProp3": { "type": "string", "index": "not_analyzed" },
"aProp4": { "type": "string", "index": "not_analyzed" }
}
}
}
}, function(err,resp,respcode){
console.log(err,resp,respcode);
});
但是...创建了索引但没有映射.... 输出是:
undefined { ok: true, acknowledged: true } 200
我做错了什么?
最佳答案
细化上述来自 Sander Spilleman 的评论中的答案。 “映射”属性需要位于“正文”属性内。我也在使用 Javascript 客户端 1.3.0,但文档仍未更新示例。
在 NPM 1.3.0 上使用 elasticsearch 提供的 javascript API 添加一个对我有用的示例
var body = {
tweet:{
properties:{
tag : {"type" : "string", "index" : "not_analyzed"},
type : {"type" : "string", "index" : "not_analyzed"},
namespace : {"type" : "string", "index" : "not_analyzed"},
tid : {"type" : "string", "index" : "not_analyzed"}
}
}
}
client.indices.putMapping({index:"tweets", type:"tweet", body:body});
关于elasticsearch:使用 javascript 创建带有映射的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22325708/