提交映射

PUT /my-index-000001PUT /my-index-000001/_mapping{  "properties": {    "email": {      "type": "keyword"    }  }}
同时提交映射到多个索引
# Create the two indicesPUT /my-index-000001PUT /my-index-000002# Update both mappingsPUT /my-index-000001,my-index-000002/_mapping{  "properties": {    "user": {      "properties": {        "name": {          "type": "keyword"        }      }    }  }}
在已存在的对象字段中增加新属性
PUT /my-index-000001{  "mappings": {    "properties": {      "name": {        "properties": {          "first": {            "type": "text"          }        }      }    }  }}PUT /my-index-000001/_mapping{  "properties": {    "name": {      "properties": {        "last": {          "type": "text"        }      }    }  }}
在已存在的字段中增加多字段
PUT /my-index-000001{  "mappings": {    "properties": {      "city": {        "type": "text"      }    }  }}PUT /my-index-000001/_mapping{  "properties": {    "city": {      "type": "text",      "fields": {        "raw": {          "type": "keyword"        }      }    }  }}
在已存在的字段中批改反对的映射参数
PUT /my-index-000001{  "mappings": {    "properties": {      "user_id": {        "type": "keyword",        "ignore_above": 20      }    }  }}PUT /my-index-000001/_mapping{  "properties": {    "user_id": {      "type": "keyword",      "ignore_above": 100    }  }}
在已存在的字段中批改映射

除了批改反对的映射参数外,不能批改已有的字段映射或字段类型。更改已有字段可能会使曾经建设索引的数据有效。

如果须要批改索引中字段的映射,能够应用新的映射创立一个新索引,而后将数据从新索引到该索引中。

PUT /my-index-000001{  "mappings" : {    "properties": {      "user_id": {        "type": "long"      }    }  }}POST /my-index-000001/_doc?refresh=wait_for{  "user_id" : 12345}POST /my-index-000001/_doc?refresh=wait_for{  "user_id" : 12346}PUT /my-new-index-000001{  "mappings" : {    "properties": {      "user_id": {        "type": "keyword"      }    }  }}# 复制文档POST /_reindex{  "source": {    "index": "my-index-000001"  },  "dest": {    "index": "my-new-index-000001"  }}
重命名字段

重命名字段会使在旧字段名称下已建设索引的数据生效。取而代之的是,增加一个别名字段作为字段名称。

PUT /my-index-000001{  "mappings": {    "properties": {      "user_identifier": {        "type": "keyword"      }    }  }}PUT /my-index-000001/_mapping{  "properties": {    "user_id": {      "type": "alias",      "path": "user_identifier"    }  }}

获取映射

GET /my-index-000001/_mappingGET /my-index-000001,my-index-000002/_mapping# 所有索引的映射GET /*/_mappingGET /_all/_mappingGET /_mapping

获取字段映射

根本语法
GET /my-index-000001/_mapping/field/user
获取单个字段的映射
PUT /publications{  "mappings": {    "properties": {      "id": { "type": "text" },      "title": { "type": "text" },      "abstract": { "type": "text" },      "author": {        "properties": {          "id": { "type": "text" },          "name": { "type": "text" }        }      }    }  }}GET publications/_mapping/field/title# 后果{   "publications": {      "mappings": {          "title": {             "full_name": "title",             "mapping": {                "title": {                   "type": "text"                }             }          }       }   }}
获取多个字段的映射
GET publications/_mapping/field/author.id,abstract,name# 后果{   "publications": {      "mappings": {        "author.id": {           "full_name": "author.id",           "mapping": {              "id": {                 "type": "text"              }           }        },        "abstract": {           "full_name": "abstract",           "mapping": {              "abstract": {                 "type": "text"              }           }        }     }   }}
匹配获取多个字段的映射
GET publications/_mapping/field/a*# 后果{   "publications": {      "mappings": {         "author.name": {            "full_name": "author.name",            "mapping": {               "name": {                 "type": "text"               }            }         },         "abstract": {            "full_name": "abstract",            "mapping": {               "abstract": {                  "type": "text"               }            }         },         "author.id": {            "full_name": "author.id",            "mapping": {               "id": {                  "type": "text"               }            }         }      }   }}