2

我有一种情况,我需要导入一堆不同的数据,这些数据最终可能会产生冲突的数据类型。我决定将所有内容都转换为字符串,然后在需要数据时再转换回来。我不知道如何使用 javascript 客户端通过 Elasticsearches (ES) 动态映射来做到这一点。

ES 在他们的文档中说什么:

{
    "mappings": {
        "my_type": {
            "dynamic_templates": [
                { "es": {
                      "match":              "*_es", 
                      "match_mapping_type": "string",
                      "mapping": {
                          "type":           "string",
                          "analyzer":       "spanish"
                      }
                }},
                { "en": {
                      "match":              "*", 
                      "match_mapping_type": "string",
                      "mapping": {
                          "type":           "string",
                          "analyzer":       "english"
                      }
                }}
            ]
}}}

在他们的文档中它说“匹配名称以_es结尾的字符串字段”。
“匹配所有其他字符串字段”:https ://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html

这是我尝试过的,但没有将所有内容都转换为字符串(也尝试过在通配符周围不加引号):

event.mappings = {
        "mytype": {
            "match": "*",
            "mapping": {
                "type": "string"
            }
        }
    }

我也试过了"match_mapping_type" : "*"

我已经尝试过:esClient.indices.putMapping({index:"myindex", type:"mytype", body:mybody}) 在响应中和 .create 函数之外。有小费吗?

4

1 回答 1

0

您的映射应如下所示

PUT /test
{
  "mappings": {
    "test": {
      "dynamic_templates": [
        {
          "en": {
            "match": "*",
            "mapping": {
              "type": "string"
            }
          }
        }
      ]
    }
  }
}

测试数据:

POST /test/test/1
{
  "nr": 1,
  "jsonDate":"2015-06-08T03:41:12-05:00",
  "bool": true
}

ES 看到的结果映射:

{
   "test": {
      "mappings": {
         "test": {
            "dynamic_templates": [
               {
                  "en": {
                     "mapping": {
                        "type": "string"
                     },
                     "match": "*"
                  }
               }
            ],
            "properties": {
               "bool": {
                  "type": "string"
               },
               "jsonDate": {
                  "type": "string"
               },
               "nr": {
                  "type": "string"
               }
            }
         }
      }
   }
}
于 2015-10-16T15:38:06.757 回答