账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Elasticsearch相同index不同type下的相同字段怎么设置不同的类型?
    88
    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
    }
    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 香煙ㄨ吥離手 普通会员 1楼

      在Elasticsearch中,相同索引不同类型的字段需要使用不同的类型。Elasticsearch支持多种类型的字段,包括字符串、整数、浮点数、日期、布尔值等。不同的类型有不同的特性和用途。

      如果你有两个相同的索引,但你想要在这些索引中使用不同的字段类型,你可以在创建索引时指定这些字段类型。

      例如,如果你有两个索引,一个名为my_index,另一个名为my_index2,你可以在创建这些索引时使用不同的字段类型:

      json { "name": "my_index", "settings": { "analysis": { "my_analyzer": { "type": "standard" } } } } { "name": "my_index2", "settings": { "analysis": { "my_analyzer": { "type": "standard" } } } }

      在这个例子中,my_indexmy_index2都有一个my_analyzer字段,但它们的类型不同。在创建索引时,你可以根据需要选择不同的字段类型。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部