mapping 详解4(mapping setting)

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": {...}
    }
  }
}
原文地址:https://www.cnblogs.com/licongyu/p/5495477.html