Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Руководство [8.17] ›Шаблоны индексов

Моделирование шаблонов из нескольких компонентов

Поскольку шаблоны могут состоять не только из нескольких компонентных шаблонов, но и самого шаблона индекса, существуют два API моделирования, чтобы определить, какими будут итоговые настройки индекса.

Чтобы смоделировать настройки, которые будут применены к определённому имени индекса:

resp = client.indices.simulate_index_template(
    name="my-index-000001",
)
print(resp)
const response = await client.indices.simulateIndexTemplate({
  name: "my-index-000001",
});
console.log(response);
POST /_index_template/_simulate_index/my-index-000001

Чтобы смоделировать настройки, которые будут применены из существующего шаблона:

resp = client.indices.simulate_template(
    name="template_1",
)
print(resp)
const response = await client.indices.simulateTemplate({
  name: "template_1",
});
console.log(response);
POST /_index_template/_simulate/template_1

Вы также можете указать определение шаблона в запросе моделирования. Это позволяет проверить, будут ли настройки применены должным образом перед добавлением нового шаблона.

resp = client.cluster.put_component_template(
    name="ct1",
    template={
        "settings": {
            "index.number_of_shards": 2
        }
    },
)
print(resp)

resp1 = client.cluster.put_component_template(
    name="ct2",
    template={
        "settings": {
            "index.number_of_replicas": 0
        },
        "mappings": {
            "properties": {
                "@timestamp": {
                    "type": "date"
                }
            }
        }
    },
)
print(resp1)

resp2 = client.indices.simulate_template(
    index_patterns=[
        "my*"
    ],
    template={
        "settings": {
            "index.number_of_shards": 3
        }
    },
    composed_of=[
        "ct1",
        "ct2"
    ],
)
print(resp2)
response = client.cluster.put_component_template(
  name: 'ct1',
  body: {
    template: {
      settings: {
        'index.number_of_shards' => 2
      }
    }
  }
)
puts response

response = client.cluster.put_component_template(
  name: 'ct2',
  body: {
    template: {
      settings: {
        'index.number_of_replicas' => 0
      },
      mappings: {
        properties: {
          "@timestamp": {
            type: 'date'
          }
        }
      }
    }
  }
)
puts response

response = client.indices.simulate_template(
  body: {
    index_patterns: [
      'my*'
    ],
    template: {
      settings: {
        'index.number_of_shards' => 3
      }
    },
    composed_of: [
      'ct1',
      'ct2'
    ]
  }
)
puts response
const response = await client.cluster.putComponentTemplate({
  name: "ct1",
  template: {
    settings: {
      "index.number_of_shards": 2,
    },
  },
});
console.log(response);

const response1 = await client.cluster.putComponentTemplate({
  name: "ct2",
  template: {
    settings: {
      "index.number_of_replicas": 0,
    },
    mappings: {
      properties: {
        "@timestamp": {
          type: "date",
        },
      },
    },
  },
});
console.log(response1);

const response2 = await client.indices.simulateTemplate({
  index_patterns: ["my*"],
  template: {
    settings: {
      "index.number_of_shards": 3,
    },
  },
  composed_of: ["ct1", "ct2"],
});
console.log(response2);
PUT /_component_template/ct1
{
  "template": {
    "settings": {
      "index.number_of_shards": 2
    }
  }
}

PUT /_component_template/ct2
{
  "template": {
    "settings": {
      "index.number_of_replicas": 0
    },
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}

POST /_index_template/_simulate
{
  "index_patterns": ["my*"],
  "template": {
    "settings" : {
        "index.number_of_shards" : 3
    }
  },
  "composed_of": ["ct1", "ct2"]
}

Ответ отображает настройки, отображения и алиасы, которые будут применены к соответствующим индексам, а также любые перекрывающиеся шаблоны, чья конфигурация будет заменена телом моделируемого шаблона или шаблонами более высокого приоритета.

{
  "template" : {
    "settings" : {
      "index" : {
        "number_of_shards" : "3",   
        "number_of_replicas" : "0",
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        }
      }
    },
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"           
        }
      }
    },
    "aliases" : { }
  },
  "overlapping" : [
    {
      "name" : "template_1",        
      "index_patterns" : [
        "my*"
      ]
    }
  ]
}

Количество фрагментов из тела моделируемого шаблона

Поле @timestamp, унаследованное от компонента ct2 шаблона

Любые перекрывающиеся шаблоны, которые соответствовали бы, но имеют более низкий приоритет

© 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/simulate-multi-component-templates.html

Spec-Zone.ru

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