PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 25, 2022

[FIXED] How to Add a Component Template to an Existing Composable Index Template

 October 25, 2022     elasticsearch, indexing, templates     No comments   

Issue

Goals:

  • Tweak the default "logs" composable index template that ships with Elasticsearch 8.
  • Change the number or replicas to 0.
  • Use the REST API

I can create a component template without issue:

PUT _component_template/no-replicas
{
  "template": {
    "settings": {
      "index": {
        "number_of_replicas": "0"
      }
    }
  }
}

However, I cannot figure out how to add the component template to the pre-installed "logs" index template, because the Create or update index template API seems to require that I pass the entire index template configuration at once.

I don't want to lose or overwrite any defaults that already exist in the "logs" index template.

Is there a way to do something like this?

PUT /_index_template/logs
{
  "ADD_COMPONENTS" : ["no-replicas"]
}

Solution

The default logs index template is composed of the logs-mappings, logs-settings and data-streams-mappings component templates.

So you can simply retrieve logs-settings...

GET _component_template/logs-settings

...add whatever settings you need to it, and store it again:

PUT _component_template/logs-settings
{
  "template": {
    "settings": {
      "index": {
        "number_of_replicas": 0,            <---- only added this
        "lifecycle": {
          "name": "logs"
        },
        "codec": "best_compression",
        "query": {
          "default_field": [
            "message"
          ]
        }
      }
    }
  },
  "version": 2,                             <---- modified this
  "_meta": {
    "description": "default settings for the logs index template installed by x-pack",
    "managed": true
  }
}

That's it, the next logs-* index that's going to be created out of the logs index template won't have any replicas.



Answered By - Val
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing