Could not get alias of newly created template in ElasticSearch V8.6.2

71 Views Asked by At

I am a rookie to the ElasticSearch, and just tried to create a template with the following command. PUT https://myip:myport/_template/templatetest

{
    "index_patterns": ["templatetest-*"],
    "order": 999,
    "settings": {
        "refresh_interval":"300s", 
        "number_of_shards":6, 
        "number_of_replicas":2
    },
    "mappings": {
        "properties": {
            "ActionName": {"type":"text"}
        }
    },
    "aliases": {
        "templatetest_all" : {}
    }
}

After this, I tried to query the alias with below command, but failed. GET https://myip:myport/_alias/templatetest_all

My question is that if there is anything wrong with my create request or query request.

Thanks.

1

There are 1 best solutions below

2
Musab Dogan On BEST ANSWER

The _template (legacy) is the old one. I recommend using _index_template.

create an _index_template

PUT _index_template/test_template
{
  "index_patterns": ["templatetest-*"],
  "order": 999,
  "settings": {
      "refresh_interval":"300s", 
      "number_of_shards":6, 
      "number_of_replicas":2
  },
  "mappings": {
      "properties": {
          "ActionName": {"type":"text"}
      }
  },
  "aliases": {
      "templatetest_all" : {}
  }
}

Create indices

PUT templatetest-001
PUT templatetest-002

Check your indices with an alias

GET _cat/indices/templatetest_all?v

You can also search your data with alias

GET templatetest_all/_search

Some recommendations:

  1. Decrease the refresh_interval to at max 30s
  2. Decrease the replica count 1