Skip to content

Instantly share code, notes, and snippets.

@zumo64
Created July 21, 2016 13:56
Show Gist options
  • Save zumo64/1bd3075940e69b7ca928b717a863b451 to your computer and use it in GitHub Desktop.
Save zumo64/1bd3075940e69b7ca928b717a863b451 to your computer and use it in GitHub Desktop.
Templates and Alias management example (ES 2.x)
PUT /test {
"mappings" : {
"my_type" : {
"dynamic_templates" : [
{
"my_integer_fields" : {
"match" : "i_*",
"mapping" : { "type" : "integer" }
}
},
{
"my_multi_strings" : {
"match_mapping_type" : "string",
"mapping" : {
"type" : "string", "index" : "analyzed",
"fields" : {
"sort" : { "type" : "string", "analyzer" : "alpha_sort"},
"raw" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
...
PUT _template/my_data_template
{
"template": "my_data*",
"settings": {
"number_of_shards": 1
},
"mappings": {
"_default_": {
"_all": {
"enabled": false
}
}
},
"order": 10
}
#https://www.elastic.co/guide/en/elasticsearch/reference/current/override-default-template.html
DELETE _template/order_prefix
GET _template/order_prefix
GET _template
#Aliases
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "employees1", "alias" : "current" } },
{ "add" : { "index" : "employees2", "alias" : "current" } }
]
}
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "employees", "alias" : "contacts" } },
{ "add" : { "index" : "clients", "alias" : "contacts" } }
]
}
POST /_aliases
{
"actions" : [
{ "remove" : { "index" : "test1", "aliases" : [ "alias1" ,"alias2" ... ] } },
...
]
}
POST
{
"actions" : [
{
"add" : {
"index" : "employees",
"alias" : "sales",
"filter" : { "term" : { "department" : "sales" } }
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment