0

Elasticsearch创建mapping的时候发现不同type的相同字段名称设置不同的type的是会报错,所以请问一下这种情况应该怎么解决???

请求连接

 PUT  http://localhost:9200/new

参数如下:

{
    "max_result_window": "1000000",
    "_source" : {
        "enabled": true
      },
      "_all" : {
        "enabled": false
      },
    "mappings": {
         "type1": {
          "properties": {
            "@timestamp" : {
              "type" : "date"
            },
            "@version" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "create_time" : {
              "index": "not_analyzed",
              "type" : "long"
            }
          }
        },
        "type2": {
          "properties": {
            "@timestamp" : {
              "type" : "date"
            },
            "@version" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "create_time" : {
              "index": "not_analyzed",
              "type" : "date"
            }
          }
        }
    }
}
 

请求结果:

 {
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "mapper [create_time] cannot be changed from type [date] to [long]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "mapper [create_time] cannot be changed from type [date] to [long]"
    },
    "status": 400
}
Simlon 3
2018-06-13 提问
2 个回答
0

这个是Elasticsearch规定死的,同一个索引内的相同字段必须是相同类型.

但是你可以曲线救国,利用copy_to,复制到另一个字段里,使用不同的类型

0

可以使用嵌套对象,或者在子属性设置成不同的那个类型,但是一旦设定了,也是不能变的

撰写答案

推广链接