Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Шаблоны индексов ›Настройка ignore_missing_component_templates

Пример использования

В следующем примере создается один шаблон компонента и шаблон индекса. Шаблон индекса ссылается на два шаблона компонентов, но существует только шаблон @package.

Создайте шаблон компонента logs-foo_component1. Его необходимо создать до шаблона индекса, так как он не является необязательным:

resp = client.cluster.put_component_template(
    name="logs-foo_component1",
    template={
        "mappings": {
            "properties": {
                "host.name": {
                    "type": "keyword"
                }
            }
        }
    },
)
print(resp)
response = client.cluster.put_component_template(
  name: 'logs-foo_component1',
  body: {
    template: {
      mappings: {
        properties: {
          'host.name' => {
            type: 'keyword'
          }
        }
      }
    }
  }
)
puts response
const response = await client.cluster.putComponentTemplate({
  name: "logs-foo_component1",
  template: {
    mappings: {
      properties: {
        "host.name": {
          type: "keyword",
        },
      },
    },
  },
});
console.log(response);
PUT _component_template/logs-foo_component1
{
  "template": {
    "mappings": {
      "properties": {
        "host.name": {
          "type": "keyword"
        }
      }
    }
  }
}

Далее, создается шаблон индекса, который ссылается на два шаблона компонентов:

  "composed_of": ["logs-foo_component1", "logs-foo_component2"]

Ранее был создан только шаблон компонента logs-foo_component1, что означает, что шаблон logs-foo_component2 отсутствует. Из-за этого в конфигурацию была добавлена следующая запись:

  "ignore_missing_component_templates": ["logs-foo_component2"],

При создании шаблона не будет проверяться, существует ли logs-foo_component2:

resp = client.indices.put_index_template(
    name="logs-foo",
    index_patterns=[
        "logs-foo-*"
    ],
    data_stream={},
    composed_of=[
        "logs-foo_component1",
        "logs-foo_component2"
    ],
    ignore_missing_component_templates=[
        "logs-foo_component2"
    ],
    priority=500,
)
print(resp)
response = client.indices.put_index_template(
  name: 'logs-foo',
  body: {
    index_patterns: [
      'logs-foo-*'
    ],
    data_stream: {},
    composed_of: [
      'logs-foo_component1',
      'logs-foo_component2'
    ],
    ignore_missing_component_templates: [
      'logs-foo_component2'
    ],
    priority: 500
  }
)
puts response
const response = await client.indices.putIndexTemplate({
  name: "logs-foo",
  index_patterns: ["logs-foo-*"],
  data_stream: {},
  composed_of: ["logs-foo_component1", "logs-foo_component2"],
  ignore_missing_component_templates: ["logs-foo_component2"],
  priority: 500,
});
console.log(response);
PUT _index_template/logs-foo
{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo_component1", "logs-foo_component2"],
  "ignore_missing_component_templates": ["logs-foo_component2"],
  "priority": 500
}

Шаблон индекса logs-foo был успешно создан. Можно создать поток данных, основанный на этом шаблоне:

resp = client.indices.create_data_stream(
    name="logs-foo-bar",
)
print(resp)
response = client.indices.create_data_stream(
  name: 'logs-foo-bar'
)
puts response
const response = await client.indices.createDataStream({
  name: "logs-foo-bar",
});
console.log(response);
PUT _data_stream/logs-foo-bar

Посмотрев на отображение потока данных, в нём будет содержаться поле host.name.

На более позднем этапе может быть добавлен отсутствующий шаблон компонента:

resp = client.cluster.put_component_template(
    name="logs-foo_component2",
    template={
        "mappings": {
            "properties": {
                "host.ip": {
                    "type": "ip"
                }
            }
        }
    },
)
print(resp)
response = client.cluster.put_component_template(
  name: 'logs-foo_component2',
  body: {
    template: {
      mappings: {
        properties: {
          'host.ip' => {
            type: 'ip'
          }
        }
      }
    }
  }
)
puts response
const response = await client.cluster.putComponentTemplate({
  name: "logs-foo_component2",
  template: {
    mappings: {
      properties: {
        "host.ip": {
          type: "ip",
        },
      },
    },
  },
});
console.log(response);
PUT _component_template/logs-foo_component2
{
  "template": {
    "mappings": {
      "properties": {
        "host.ip": {
          "type": "ip"
        }
      }
    }
  }
}

Это не повлияет немедленно на поток данных. Отображение host.ip будет отображаться в отображении потока данных только при автоматической ротации потока данных в следующий раз или при ручном запуске ротации:

resp = client.indices.rollover(
    alias="logs-foo-bar",
)
print(resp)
response = client.indices.rollover(
  alias: 'logs-foo-bar'
)
puts response
const response = await client.indices.rollover({
  alias: "logs-foo-bar",
});
console.log(response);
POST logs-foo-bar/_rollover

© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/_usage_example.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API