zoukankan      html  css  js  c++  java
  • Elasticsearch之索引模板

    解决的问题

      当索引类型和配置信息都一样,就可以使用索引模板来处理,不然我们就会手动创建索引。

    创建索引模板

    PUT _template/2019
    {
      "index_patterns": ["20*", "product1*"],   
      "settings":{   
        "number_of_shards": 2,
        "number_of_replicas": 1
      },
      "mappings":{  
        "doc":{
          "properties":{
            "ip":{
              "type":"keyword"
            },
            "method":{
              "type": "keyword"
            }
          }
        }
      }
    }
    
    # index_patterns是索引模式,指当创建以20和product1开头的索引时,使用该索引模板
    # 在settings设置中,我们自定义为该索引分配3个主分片。复制分片不变
    # mappings中指定映射关系

    查看索引模板

    GET _cat/templates
    GET _template
    GET _template/2019
    GET _template/20*

    索引模板的使用

    添加数据并且查询模板是否使用上

    PUT 20190101/doc/1
    {
      "ip": "127.0.0.1",
      "method":"GET"
    }
    
    PUT 20190102/doc/2
    {
      "ip":"192.168.1.1",
      "method":"POST"
    }
    
    PUT product1_log/doc/1
    {
      "ip":"127.0.0.1",
      "method":"GET"
    }
    
    GET 2019*/doc/_search
    {
      "query": {
        "match_all": {}
      }
    }
    
    GET 20190101

    查询结果模板使用上了

    {
      "20190101" : {
        "aliases" : { },
        "mappings" : {
          "doc" : {
            "properties" : {
              "ip" : {
                "type" : "keyword"
              },
              "method" : {
                "type" : "keyword"
              }
            }
          }
        },
        "settings" : {
          "index" : {
            "creation_date" : "1566821645952",
            "number_of_shards" : "2",
            "number_of_replicas" : "1",
            "uuid" : "Tzqx1mKvTmiBMfaOfhQAwg",
            "version" : {
              "created" : "6050499"
            },
            "provided_name" : "20190101"
          }
        }
      }
    }  

    多模板匹配

    PUT _template/2018_1
    {
      "index_patterns": ["2018*"],
      "order":0,
      "settings":{
        "number_of_shards": 2
      }
    }
    
    
    PUT 2018010101/doc/1
    {
      "method":"GET"
    }
    GET 2018010101/_settings

    删除模板

    DELETE _template/2018*
  • 相关阅读:
    C#访问MySql连接字符串
    简单的async和await用法
    Nuget新旧地址更换
    【NPS】nps分多少算好
    「干货」什么Linux是邮件服务器?
    「干货」编程语言十大经典算法,你知道几个?
    实验干货分享:用Go语言实现分布式缓存开发之map
    开发微信小程序游戏真的有手就行吗?
    图数据库Neo4j的介绍与使用
    干货分享:什么是Java设计三大工厂模式?
  • 原文地址:https://www.cnblogs.com/Alexephor/p/11414741.html
Copyright © 2011-2022 走看看