elasticsearch 配置模板

GET _cat/templates
PUT _template/template_base    【错误做法,勿执行】
{
    "template" : "*",
    "order" : 0,
    "settings" : {
        "number_of_shards" : 5,
        "number_of_replicas" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false }
        }
    }
}
curl -XGET "http://192.168.1.11:9200/_cat/templates"
curl -XPUT "http://192.168.1.11:9200/_template/template_base" -H 'Content-Type: application/json' -d'  【错误做法,勿执行】
{ "template" : "*", "order" : 0, "settings" : { "number_of_shards" : 5, "number_of_replicas" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : false } } } }'

 

【正确做法,使用系统默认的mappings】 不然会的导致报错:[Rejecting mapping update to [.monitoring-es-6-2019.06.04] as the final mapping would have more than 1 type: [doc, type1]]

PUT _template/template_base
{
    "template" : "*",
    "order" : 0,
    "settings" : {
        "number_of_shards" : 5,  #分片数量
        "number_of_replicas" : 1  #副本数量 < 可用节点数
    },
    "mappings": {
    "doc": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "data": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "fields": {
          "properties": {
            "host_ip": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "project": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "type": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        },
        "host": {
          "properties": {
            "name": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        },
        "level": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "log": {
          "properties": {
            "file": {
              "properties": {
                "path": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          }
        },
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "server": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "source": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tags": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "time": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

 

posted @ 2019-06-03 12:19  chenjianwen  阅读(2132)  评论(0编辑  收藏  举报