本文介绍了ElasticSearch client.indices.putMapping总是失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的不了解文档.即使在阅读了一些SO问题和答案之后(例如:这一个).我有这个代码
I really don't understand the docs. Even after reading a few SO questions and answers (ex: this one). I have this code
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);
});
我总是得到
我在做什么错了?
我的索引是新创建的,没有添加文档或当前定义的任何类型.这是我要在添加文档和建立索引之前将映射设置为新的空白索引.
My index is newly created, and there are no documents added or any types currently defined. This is a new, blank, index that I want to set mappings to before adding and indexing documents.
推荐答案
动态模板声明应与映射类型的 properties
处于同一级别,因此您的代码应如下所示:
Dynamic templates declarations should go at the same level as the properties
of a mapping type, so your code should look like this instead:
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);
});
这篇关于ElasticSearch client.indices.putMapping总是失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!