dynamic mapping策略

dynamic:
1.true:遇到陌生字段就dynamic mapping
2.false:遇到陌生字段就忽略
3:strict:遇到陌生字段就报错

PUT /lib8

{
  "settings":{
    "number_of_shards":3,
    "number_of_replicas":0
  },
  "mappings":{
    "user":{
      "dynamic":"strict",
      "properties":{
        "name":{
          "type":"text"
        },
        "address":{
          "type":"object",
          "dynamic":true
        }
      }
    }
  }
}

会报错
PUT /lib8/user/1

{
  "name":"lisi",
  "age":20,
  "address":{
    "province":"beijing",
    "city":"beijing"
  }
}

date_detection:默认会按照一定格式识别date,比如:yyyy-MM-dd
可以手动关闭某个type的date_detection
PUT /lib8

{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 0
  },
  "mappings": {
    "user": {
      "date_detection": false
    }
  }
}

定制dynamic mapping template(type)
PUT /my_index

{
  "mappings": {
    "my_type":{
      "dynamic_templates":[
          {
            "en":{
              "match":"*_en",
              "match_mapping_type":"string",
              "mapping":{
                "type":"text",
                "analyzer":"english"
              }
            }
          }
        ] 
    }
  }
}

使用模板:
PUT /my_index/my_type/3

{
  "title_en":"this is my dog"
}

PUT /my_index/my_type/5

{
  "title":"this is my cat"
}

GET my_index/my_type/_search

{
  "query": {
    "match": {
      "title": "is"
    }
  }
}

GET my_index/my_type/_search

{
  "query": {
    "match": {
      "title_en": "is"
    }
  }
}

你可能感兴趣的:(dynamic mapping策略)