반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

index template 본문

ElasticStack/Elasticsearch

index template

닉의네임 2021. 10. 13. 23:23
반응형

Elasticsearch : 

PUT _component_template/component_template1
{
  "template": {
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}

 

PUT _component_template/runtime_component_template
{
  "template": {
    "mappings": {
      "runtime": { 
        "day_of_week": {
          "type": "keyword",
          "script": {
            "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))"
          }
        }
      }
    }
  }
}
PUT _index_template/template_1
{
  "index_patterns": ["te*", "bar*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas":0
    },
    "mappings": {
      "_source": {
        "enabled": true
      },
      "properties": {
        "host_name": {
          "type": "keyword"
        },
        "created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z yyyy"
        }
      }
    },
    "aliases": {
      "mydata": { }
    }
  },
  "priority": 500,
  "composed_of": ["component_template1", "runtime_component_template"], 
  "version": 3,
  "_meta": {
    "description": "my custom"
  }
}

index pattern 에 맞는  데이터 입력

 

POST test/_doc/1
{
  "host_name": "localhost"
}

 

index meta data 확인 

{
"version": 4,
"mapping_version": 1,
"settings_version": 1,
"aliases_version": 1,
"routing_num_shards": 1024,
"state": "open",
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "test",
"creation_date": "1634135526525",
"number_of_replicas": "0",
"uuid": "PvNGwN24Tpm454KGxGlbSA",
"version": {
"created": "7130499"
}
}
},
"mappings": {
"_doc": {
"runtime": {
"day_of_week": {
"type": "keyword",
"script": {
"source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))",
"lang": "painless"
}
}
},
"properties": {
"@timestamp": {
"type": "date"
},
"created_at": {
"format": "EEE MMM dd HH:mm:ss Z yyyy",
"type": "date"
},
"host_name": {
"type": "keyword"
}
}
}
},
"aliases": [
"mydata"
],
"primary_terms": {
"0": 1
},
"in_sync_allocations": {
"0": [
"i-GeIPcpRJusyzYNErecnQ"
]
},
"rollover_info": { },
"system": false,
"timestamp_range": {
"unknown": true
}
}
반응형

'ElasticStack > Elasticsearch' 카테고리의 다른 글

[es] function score Query  (0) 2021.12.20
[es] plugin 4 - custom analyzer 사용  (0) 2021.12.15
[es] plugin 3 - custom analyzer  (0) 2021.12.12
[es] Analyzer 01  (0) 2021.12.08
[es] plugin 1 (mvn 설치)  (0) 2021.11.10
Comments