Elastic的字符串属性分成:keyword 和 text ,一般我们会把所有字符串设置为 keyword:

默认字段属性的设置规则:

PUT /test_idx
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "month": {
      "dynamic": "true",
      "dynamic_templates": [
        {
          "regex_template": {
            "match_pattern": "regex",
            "mapping": {
              "type": "keyword"
            },
            "match": "^(?!.*?_time|is_.*|.*?_cnt|.*?_count|.*?_dbl|.*?_double|.*?_obj|.*?_object).*$"
          }
        },
        {
          "time_template": {
            "mapping": {
              "format": "strict_date_time || yyyy-MM-dd HH:mm:ss || epoch_millis || epoch_second || yyyy-MM-dd",
              "type": "date"
            },
            "match": "*_time"
          }
        },
        {
          "double_template": {
            "mapping": {
              "type": "double"
            },
            "match": "*_dbl"
          }
        },
        {
          "double_template": {
            "mapping": {
              "type": "double"
            },
            "match": "*_double"
          }
        },
        {
          "integer_template": {
            "mapping": {
              "type": "integer"
            },
            "match": "is_*"
          }
        },
        {
          "long_template": {
            "mapping": {
              "type": "integer"
            },
            "match": "*_cnt"
          }
        },
        {
          "long_template": {
            "mapping": {
              "type": "integer"
            },
            "match": "*_count"
          }
        },
        {
          "object_template": {
            "mapping": {
              "type": "object"
            },
            "match": "*_obj"
          }
        },
        {
          "object_template": {
            "mapping": {
              "type": "object"
            },
            "match": "*_object"
          }
        }
      ]
    }
  }
}  
View Code

相关文章: