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

相關文章
相關標籤/搜索