PUT /my-index-000001 PUT /my-index-000001/_mapping { "properties": { "email": { "type": "keyword" } } }
# Create the two indices PUT /my-index-000001 PUT /my-index-000002 # Update both mappings PUT /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 } } }
除了修改支持的映射參數外,不能修改已有的字段映射或字段類型。更改已有字段可能會使已經創建索引的數據無效。app
若是須要修改索引中字段的映射,能夠使用新的映射建立一個新索引,而後將數據從新索引到該索引中。ide
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" } }
重命名字段會使在舊字段名稱下已創建索引的數據失效。取而代之的是,添加一個別名字段做爲字段名稱。code
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/_mapping GET /my-index-000001,my-index-000002/_mapping # 全部索引的映射 GET /*/_mapping GET /_all/_mapping GET /_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" } } } } } }