Elasticsearch 参考指南(Put Mapping)

Put Mapping

PUT mapping API容许你向现有索引添加字段,或者仅更改现有字段的搜索设置。segmentfault

PUT twitter 
{}

PUT twitter/_mapping 
{
  "properties": {
    "email": {
      "type": "keyword"
    }
  }
}
  • 建立一个名为twitter的索引,不须要任何映射。
  • 使用PUT mapping API添加一个名为email的新字段。

有关如何定义映射的更多信息能够在映射部分中找到。app

在7.0.0以前,映射定义用于包含类型名称,虽然如今不同意在请求中指定类型,可是若是设置了请求参数 include_type_name,仍然能够提供类型,有关详细信息,请参见 删除映射类型

多索引

PUT mapping API能够应用于单个请求的多个索引,例如,咱们能够同时更新twitter-1twitter-2的映射:code

# Create the two indices
PUT twitter-1
PUT twitter-2

# Update both mappings
PUT /twitter-1,twitter-2/_mapping 
{
  "properties": {
    "user_name": {
      "type": "text"
    }
  }
}
  • 注意,指定的索引(twitter-1,twitter-2)遵循多索引名称和通配符格式。

更新字段映射

一般,没法更新现有字段的映射,这条规则有一些例外,例如:对象

  • 能够向对象字段添加新properties
  • 能够向现有字段添加新的多字段。
  • 能够更新ignore_above参数。

示例:索引

PUT my_index 
{
  "mappings": {
    "properties": {
      "name": {
        "properties": {
          "first": {
            "type": "text"
          }
        }
      },
      "user_id": {
        "type": "keyword"
      }
    }
  }
}

PUT my_index/_mapping
{
  "properties": {
    "name": {
      "properties": {
        "last": { 
          "type": "text"
        }
      }
    },
    "user_id": {
      "type": "keyword",
      "ignore_above": 100 
    }
  }
}
  • 建立一个索引,其中name对象字段下有first字段,user_id字段。
  • name对象字段下添加last字段。
  • 从默认值0更新ignore_above设置。

每一个映射参数指定是否能够在现有字段上更新其设置。get

相关文章
相关标签/搜索