elasticsearch操作索引映射以及相关命令

Mapping类似于数据库中的表定义,主要有以下几个作用:

  1. 定义索引中字段的名称
  2. 定义字段的数据类型,例如:字符串、数字…
  3. 倒排索引的相关配置,是否分词,字段分词器选择等

 所有数据操作命令基于官方提供的样本测试数据,ES复杂操作的学习使用,需要样本数据看这里:官方样本数据

1.创建索引映射

PUT /my_index
{
  "mappings": {
    "properties": {
      "age":{"type": "integer"},
      "email":{"type": "keyword"},
      "name":{"type": "text"}
    }
  }
}

2.已存在的映射添加新的映射字段

{
  "properties":{
    "employee-id":{
      "type":"keyword",
      "index":false
    }
  }
}

3.映射进行修改

不能直接修改索引的映射,如果必须要修改可以重新创建索引映射在进行数据转移

创建新的索引

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

4.迁移数据(旧索引迁移新索引),source-index是老索引,dest-index是新索引

POST _reindex
{
  "source": {
    "index": "bank",
    "type": "account"
  },
  "dest": {
    "index": "new_bank"
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值