栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Index Template 和Dynamic Template

Index Template 和Dynamic Template

//数字字符串被映射成text,日期字符串被映射成日期
PUT ttemplate/_doc/1
{
  "someNumber":"1",
  "someDate":"2019/01/01"
}

GET ttemplate/_mapping

//创建一个默认的template
PUT _template/template_default
{
  "index_patterns": ["*"],
  "order": 0,
  "version": 1,
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  }
}

PUT /_template/template_test
{
  "index_patterns": ["test*"],
  "order": 1,
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 2
  },
  "mappings": {
    "date_detection": false,
    "numeric_detection": true
  }
}

//查看template信息
GET /_template/template_default
GET /_template/temp*   

//写入新的数据,index以test开头
PUT testtemplate/_doc/1
{
  "someNumber":"1",
  "someDate":"2019/01/01"
}

GET testtemplate/_mapping
GET testtemplate/_settings


PUT testmy
{
  "settings": {
    "number_of_replicas": 5
  }
}
PUT testmy/_doc/1
{
  "key":"value"
}

GET testmy/_settings

//Dynamic Mapping 根据类型和字段名
DELETE my_index
PUT my_index/_doc/1
{
  "firstName":"Ruan",
  "isVIP":"true"
}
GET my_index/_mapping
DELETE my_index
PUT my_index
{
  "mappings": {
    "dynamic_templates": [
      {
        "strings_as_boolean":{
          "match_mapping_type":"string",
          "match":"is*",
          "mapping":{
            "type":"boolean"
          }
        }
      },
      {
        "string_as_keywords":{
          "match_mapping_type":"string",
          "mapping":{
            "type":"keyword"
          }
        }
      }
    ]
  }
}

PUT my_index
{
  "mappings": {
    "dynamic_templates": [
      {
        "full_name":{
          "path_match":"name.*",
          "path_unmatch":"*.middle",
          "mapping":{
            "type": "text",
            "copy_to":"full_name"
          }
        }
      }
    ]
  }
}

PUT my_index/_doc/1
{
  "name":{
    "first":"John",
    "middle":"Winston",
    "last":"Lennon"
  }
}

GET my_index/_search?q=full_name:John

GET my_index/_mapping

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/582135.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号