# 索引->别名/是否存在/类型存在

## 索引->别名/是否存在/是否类型存在

## Indices Exists /索引是否存在

用来检查如果 index ( indics )是否存在。例如:

```
curl -XHEAD 'localhost:9200/twitter?pretty'
```

HTTP状态码表示index存在与否。404意味着它不存在，200即存在。

## Types Exists/类型是否存在

用于检查是否一个类型存在于索引。

```
HEAD twitter/_mapping/tweet
```

HTTP状态码表示type存在与否。404意味着它不存在，200即存在。

## Index Aliases /索引别名

这是一个示例将别名`alias1`指定索引`test1`:

```
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } }
    ]
}
```

这是删除相同的别名:

```
POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } }
    ]
}
```

重命名一个别名是一个简单的删除然后添加操作在同一个API。这个操作是原子的,不需要担心短时间内的别名不指向索引:

```
POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}
```

将别名指向一个以上的索引只是几个添加操作:

```
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}
```

可以指定多个索引的操作,采用索引数组的语法:

```
POST /_aliases
{
    "actions" : [
        { "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }
    ]
}
```

在一个动作指定多个别名,相应的别名数组语法也存在。

在上面的示例中,正则匹配模式还可以用于别名关联到多个索引共享一个共同的名字:

```
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test*", "alias" : "all_test_indices" } }
    ]
}
```

更多复杂操作请看官方文档:[Index Aliases](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-aliases.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/33-apis/341suo-yin-api/suo-5f15-3e-bie-540d-cun-5728-lei-xing-cun-zai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
