allanbatista
12/22/2016 - 5:38 PM

Criação de Templates no elasticsearch

Criação de Templates no elasticsearch

# POST http://localhost:9200/_template/default_template

{
  "template": "*",
  "mappings": {
    "dynamic_templates": [
      {
        "timestamp": {
          "match": "*_at",
          "mapping": {
            "type": "date",
            "format": "strict_date_optional_time||epoch_millis"
          }
        }
      },
      {
        "integers": {
          "match_mapping_type": "long",
          "mapping": {
            "type": "integer"
          }
        }
      },
      {
        "strings": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "text",
            "fields": {
              "raw": {
                "type":  "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    ]
  }
}
POST /_template/template_logs

{
  "template": "logs*",
  "mappings": {
    "log": {
      "properties": {
        "host": {
          "index": "not_analyzed",
          "type": "string"
        },
        "server_name": {
          "index": "not_analyzed",
          "type": "string"
        },
        "hostname": {
          "index": "not_analyzed",
          "type": "string"
        },
        "request": {
          "type": "object",
          "properties": {
            "url": {
              "index": "not_analyzed",
              "type": "string"
            },
            "method": {
              "index": "not_analyzed",
              "type": "string"
            },
            "params": {
              "type": "string"
            },
            "fullpath": {
              "index": "not_analyzed",
              "type": "string"
            },
            "origin_ip": {
              "index": "not_analyzed",
              "type": "string"
            },
            "headers": {
              "index": "not_analyzed",
              "type": "string"
            }
          }
        },
        "sale_system": {
          "index": "not_analyzed",
          "type": "string"
        },
        "response": {
          "type": "object",
          "properties": {
            "status": {
              "type": "integer"
            },
            "body": {
              "index": "not_analyzed",
              "type": "string"
            }
          }
        },
        "created_at": {
          "format": "yyyy-MM-dd'T'HH:mm:ssZZ",
          "type": "date"
        },
        "account": {
          "type": "object",
          "properties": {
            "name": {
              "index": "not_analyzed",
              "type": "string"
            },
            "id": {
              "index": "not_analyzed",
              "type": "string"
            },
            "active": {
              "type": "boolean"
            }
          }
        },
        "api_manager": {
          "type": "object",
          "properties": {
            "token": {
              "index": "not_analyzed",
              "type": "string"
            },
            "description": {
              "index": "not_analyzed",
              "type": "string"
            }
          }
        }
      }
    }
  }
}
{
  "template": "synchronizer-logs-*",
  "mappings": {
    "log": {
      "dynamic_templates": [
        {
          "dimensions": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ],
      "properties": {
        "created_at": {
          "type": "date",
          "format": "yyyy-MM-dd'T'HH:mm:ssZZ"
        },
        "type": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}