es 使用curl创建索引模板

15 篇文章 3 订阅

创建索引模板,所有以people_trail开头的索引都会走这个索引模板

curl -DPUT '127.0.0.1:9200/_template/people_trail' -d '{
  "template": "people_trail*",
  "settings": {
    "index": {
	  "number_of_shards": "1",
	  "number_of_replicas": "0",
      "analysis": {
        "analyzer": {
          "pinyin": {
            "tokenizer": "pinyin_tokenizer"
          }
        },
        "tokenizer": {
          "pinyin_tokenizer": {
            "type": "pinyin",
            "keep_joined_full_pinyin": true
          }
        }
      }
    }
  },
  "mappings": {
    "_default_": {
      "_all": {
        "enabled": true,
        "analyzer": "standard"
      },
      "dynamic_templates": [
        {
          "xms": {
			"mapping": {
			"fields": {
				"py": {
					"analyzer": "pinyin",
					"type": "text"
				}
			},
				"type": "keyword"
			},
			"match_mapping_type": "string",
			"match": "XM"
			}
		},
		{	  
		  "strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword",
              "fields": {
                "full": {
                  "type": "text",
                  "analyzer": "standard"
                }
              }
            }
          }
        }
      ]
    }
  }
}'

查询所有模板

curl -XGET 127.0.0.1:9200/_cat/templates

curl -XGET 127.0.0.1:9200/_cat/templates
address_type  address_type* 0 
article_type* article_type* 0 
people_trail  people_trail* 0 
article_type  lw_*          0 

查看某一个模板

curl -XGET http://127.0.0.1:9200/_template/article_type?pretty

curl -XGET http://127.0.0.1:9200/_template/article_type?pretty
{
  "article_type" : {
    "order" : 0,
    "template" : "lw_*",
    "settings" : {
      "index" : {
        "analysis" : {
          "analyzer" : {
            "pinyin" : {
              "tokenizer" : "pinyin_tokenizer"
            }
          },
          "tokenizer" : {
            "pinyin_tokenizer" : {
              "type" : "pinyin",
              "keep_joined_full_pinyin" : "true"
            }
          }
        }
      }
    },
    "mappings" : {
      "_default_" : {
        "dynamic_templates" : [
          {
            "xms" : {
              "mapping" : {
                "fields" : {
                  "py" : {
                    "analyzer" : "pinyin",
                    "type" : "text"
                  }
                },
                "type" : "keyword"
              },
              "match_mapping_type" : "string",
              "match" : "XM"
            }
          },
          {
            "strings" : {
              "mapping" : {
                "type" : "keyword",
                "fields" : {
                  "full" : {
                    "analyzer" : "standard",
                    "type" : "text"
                  }
                }
              },
              "match_mapping_type" : "string"
            }
          }
        ],
        "_all" : {
          "analyzer" : "standard",
          "enabled" : true
        }
      }
    },
    "aliases" : { }
  }
}

删除一个索引模板

curl -XDELETE http://127.0.0.1:9200/_template/article_type

curl -XDELETE http://127.0.0.1:9200/_template/article_type
{"acknowledged":true}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值