我真的不明白医生的意思。即使在阅读了一些这样的问题和答案之后(例如:this one)。我有这个密码
let indexMapping = {
'foo': {
name: { type: 'string', index: 'analyzed' },
value: { index: 'no' },
dynamic_templates: [ {
customRule: {
path_match: 'bar.*',
mapping: { type: '{dynamic_type}', index: 'no' }
}
} ]
}
};
let indexName = 'foos';
let typeName = 'foo';
client.indices.putMapping({
index: indexName,
type: typeName,
[typeName]: {
properties: indexMapping[typeName]
}
}).catch(function (err) {
console.error(err.stack || err);
});我总是能得到
错误: action_request_validation_exception验证失败: 1:映射源为空;
我做错了什么?
更多信息
我的索引是新创建的,并且没有添加任何文档或当前定义的任何类型。这是一个新的、空白的索引,我想在添加和索引文档之前设置映射。
发布于 2016-08-02 05:12:33
动态模板声明应该与映射类型的properties级别相同,因此您的代码应该如下所示:
let indexName = 'foos';
let typeName = 'foo';
let indexMapping = {
'properties': {
[typeName]: {
name: { type: 'string', index: 'analyzed' },
value: { type: 'string', index: 'no' }
}
},
'dynamic_templates': [ {
customRule: {
path_match: 'bar.*',
mapping: { type: '{dynamic_type}', index: 'no' }
}
} ]
};
client.indices.putMapping({
index: indexName,
type: typeName,
body: indexMapping
}).catch(function (err) {
console.error(err.stack || err);
});发布于 2016-08-01 21:07:53
您使用的语法有点不正确,您的最后调用应该如下所示:
client.indices.putMapping({
index: 'foos',
type: 'foo',
body: {
"foo": {
properties: {
name: {
type: 'string',
index: 'analyzed'
},
value: {
index: 'no'
},
dynamic_templates: [{
customRule: {
path_match: 'bar.*',
mapping: {
type: '{dynamic_type}',
index: 'no'
}
}
}]
}
}
}
}).catch(function(err) {
console.error(err.stack || err);
});还要注意,您必须像为value那样为name定义一个类型,而动态模板部分也缺少fields对象。
https://stackoverflow.com/questions/38708006
复制相似问题