我正在开发一个应用程序,我需要映射 json 数据以存储在 Elasticsearch 中。 json数据中的字段数量是动态的。那么我该如何针对这种情况进行映射呢?
映射片段
var fs = uploadedFiles[0].fd;
var xlsxRows = require('xlsx-rows');
var rows = xlsxRows(fs);
console.log(rows);
client.indices.putMapping({
"index": "testindex",
"type": "testtype",
"body": {
"testtype": {
"properties": {
"Field 1": {
"type": "string"
},
"Field 3": {
"type": "string"
},
"Field 2":{
"type":"string"
} .....
//Don't know how many fields are in json object.
}
}
}
}, function (err, response) {
if(err){
console.log("error");
}
console.log("REAPONCE")
console.log(response);
});
这是我的示例 json 数据 //行结果
[
{ Name: 'paranthn', Age: '43', Address: 'trichy' },
{ Name: 'Arthick', Age: '23', Address: 'trichy' },
{ Name: 'vel', Age: '24', Address: 'trichy' } //property fields
]
NOTE: The number of property fields are dynamic.
最佳答案
ES 将始终尽最大努力推断文档中未定义映射的字段的正确类型和 set sensible defaults 。
仅当您需要对除默认设置之外的某些字段进行某些特殊处理时才需要映射,例如指定索引分析器、搜索分析器、是否需要分析字符串字段、指定子字段不同的分析仪等。
如果您不需要这些,那么您可以让 ES 推断文档的映射。
关于javascript - Elasticsearch : How can i map json data having dynamic number of fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32471449/