javascript - Elasticsearch : How can i map json data having dynamic number of fields

标签 javascript json elasticsearch mapping

我正在开发一个应用程序,我需要映射 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/

相关文章:

javascript - 在 JQuery 中读取 json

javascript - jquery 为内容设置正确的高度

javascript - 如何在JavaScript中使用window.history?

php - 如何解决 cURL Post 不发布数据的问题?

ElasticSearch 安全和端口

javascript - 如何解决 Promise pending 的问题

json - 获取 package.json 文件中另一个字段的值(npm)

java - 按 ID 对 JSON 数组排序

elasticsearch - 在_update_by_query期间插入丢失的文档

elasticsearch - 如何汇总几个替代术语?