Elasticsearch-Mapping和数据迁移

mapping:mapping就好比sql建表指定的数据类型

实例:
PUT /new_bank
{
  "mappings": {
    "properties": {
      "account_number": {
        "type": "long"
      },
      "address": {
        "type": "text"
      },
      "age": {
        "type": "integer"
      },
      "balance": {
        "type": "long"
      },
      "city": {
        "type": "text"
      },
      "email": {
        "type": "text"
      },
      "employer": {
        "type": "text"
      },
      "firstname": {
        "type": "text"
      },
      "gender": {
        "type": "keyword"
      },
      "lastname": {
        "type": "text"
      },
      "state": {
        "type": "text"
      }
    }
  }
}

2.es新增字段

PUT /test_index
{
  "mappings": {
    "properties": {
      "name":"111"
    }
  }
}

3.新增字段

PUT /test_index/_mapping
{
  "properties":{
    "age1":{
      "type":"long"
    }
  }
}

4.es不支持更新字段,如果要修改字段类型,那么需要新建index来进行转移

以下有两种写法,这两种写法有什么区别:

要知道es数据组成的话分为 

 index    ->    sql的database

type ->   sql的表

document ->数据

在es6之后删除了type,为什么呢?

在关系型数据库中table是独立的(独立存储),但es中同一个index中不同type是存储在同一个索引中的(lucene的索引文件),因此不同type中相同名字的字段的定义(mapping)必须一致。不同类型的“记录”存储在同一个index中,会影响lucene的压缩性能,如果是有设置type那么使用第一种否则使用第二种

post _reindex

      "source":{

          "index":"老索引" 

       },

      “dest":{

             "index":"新索引"

        }

 2. 将老索引的type数据进行迁移

post _reindex

{

     "source":{

         "index":"oldIndexName",

          "type":"老索引_type的值"

        }

       "dest":{

            "index::"newIndex"

       }

}

}

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值