ES (7.10.2)学习系列之 对mapping的操作

188 阅读1分钟

  • GET {{es-url}}/indexName/_mapping

出参

{
    "test-xizihao": {
        "mappings": {
            "properties": {
                "age": {
                    "type": "long"
                },
                "birthday": {
                    "type": "date",
                    "format": "yyyy-MM-dd"
                },
                "birthday_time": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "id": {
                    "type": "long"
                },
                "interesting": {
                    "type": "text"
                },
                "name": {
                    "type": "keyword"
                },
                "sex": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }

新增字段

  • PUT {{es-url}}/indexName/_mapping

入参

{
  "properties": {
    "job": {
      "type": "keyword",
      "index": false   //索引选项控制是否对字段值建立索引。 它接受truefalse,默认为true。未索引的字段不可查询。
    }
  }
}
​

更新字段

对于已经存在的映射字段,我们不能更新。更新必须创建新的索引进行数据迁移

数据迁移

先创建新的索引 然后执行迁移 语句(迁移后老索引的数据仍然存在)

  • POST {{es-url}}/_reindex
{
  "source": {   //老索引
    "index": "test-xizihao"
  },
  "dest": {     //目标索引
    "index": "test-xizihao_new"
  }
}