標籤:
mapping type
映射設定一般發生在:
1. 增加新的 index 的時候,添加 mapping type,對 fields 的映射進行設定
PUT twitter { "mappings": { "tweet": { "properties": { "message": { "type": "string" } } } }}
2. 為 index 增加新的 mapping type,對 fields 的映射進行設定
PUT twitter/_mapping/user { "properties": { "name": { "type": "string" } }}
3. 為已有 mapping type 增加新的 fields 映射設定
PUT twitter/_mapping/tweet { "properties": { "user_name": { "type": "string" } }}
設定方式
1. 在 PUT 請求體中給出完整的 mapping 設定
PUT twitter { "mappings": { //mappings 對象,說明進行 mapping 設定 "tweet": { //指定 mapping type "properties": { //指定 mapping type 的 properties 設定 "message": { //對欄位 message 的映射進行設定 "type": "string" //mapping 參數配置 } } } }}
增加 index 的時候,除了可以設定 mapping type,還可以對 index 進行設定,比如配置自訂 analyzer、索引分區個數設定等
PUT /my_index{ "settings": { "analysis": { "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "autocomplete_filter" ] } } } }, "mappings": { "my_type": { "properties": { "text": { "type": "string", "analyzer": "autocomplete" } } } }}
2. 在 PUT 請求 URI 中指定 type,並在請求體中給出 type 的各項設定
PUT twitter/_mapping/user { "properties": { //指定 mapping type 的 properties 設定 "name": { //對欄位 message 的映射進行設定 "type": "string" //mapping 參數配置 } }}
3. 一個完整的 mapping type 設定包括:Meta-fields 和 Fields 或者 properties 設定
PUT my_index{ "mappings": { "type_1": { "properties": {...} //properties 設定 }, "type_2": { "_all": { //meta-fields 設定 "enabled": false }, "properties": {...} } }}
mapping 詳解4(mapping setting)