# How do I apply policy to index?

**URL:** <https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770>\
**Category:** OpenSearch\
**Created:** [June 21, 2023, 9:38am UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770 "2023-06-21T09:38:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cucukaka](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cucukaka](https://forum.opensearch.org/u/cucukaka)\
**Post date:** [June 21, 2023, 9:38am UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770/1 "2023-06-21T09:38:55Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
opensearch 2.7.0

**Describe the issue** :  
why didn’t apply policy in index?  
I follow these steps(refer to [Policies - OpenSearch documentation](https://opensearch.org/docs/latest/im-plugin/ism/policies/#sample-policy-with-ism-template-for-auto-rollover))  
The first index created **but** next index **did not create** even thought shard’s **size over** 30gb(setting value in policy)  
And In the Opensearch Dashboards - Policy managed indices menu  
I can see this - **Missing rollover\_alias index setting [index=log-2023.06.19-000001]"**

 ![MicrosoftTeams-image (28)](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/5/530cc0277b91fa2cfefac884950c56dc64e83d1a.png)

1. creat policy

```auto
{
    "id": "data-policy",
    "seqNo": 730,
    "primaryTerm": 2,
    "policy": {
        "policy_id": "data-policy",
        "description": "hot warm delete workflow",
        "last_updated_time": 1687283567536,
        "schema_version": 17,
        "error_notification": null,
        "default_state": "hot",
        "states": [
            {
                "name": "hot",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "rollover": {
                            "min_index_age": "1d",
                            "min_primary_shard_size": "30gb"
                        }
                    }
                ],
                "transitions": [
                    {
                        "state_name": "warm"
                    }
                ]
            },
            {
                "name": "warm",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "replica_count": {
                            "number_of_replicas": 5
                        }
                    }
                ],
                "transitions": [
                    {
                        "state_name": "delete",
                        "conditions": {
                            "min_index_age": "63d"
                        }
                    }
                ]
            },
            {
                "name": "delete",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "delete": {}
                    }
                ],
                "transitions": []
            }
        ],
        "ism_template": [
            {
                "index_patterns": [
                    "log*"
                ],
                "priority": 0,
                "last_updated_time": 1686594538983
            }
        ]
    }
}

```

1. put /\_template/ism\_rollover\_app

```auto
PUT /_template/ism_rollover_app
{
  "index_patterns": "log*",
  "settings":{
    "index":{
      "opendistro.index_state_management.rollover_alias": "log"
      }
  }
}

```

1. create index template

```auto
{
  "index_patterns": [
    "log*"
  ],
  "template": {
    "settings": {
      "index.number_of_shards": "3",
      "index.number_of_replicas": "1"
    },
    "aliases": {
      "log": {}
    }
  },
  "composed_of": [],
  "priority": "0",
  "_meta": {
    "flow": "simple"
  },
  "name": "log"
}

```

1. put first data

```auto
PUT /%3Clog-%7Bnow%2Fd%7D-000001%3E
{
  "aliases": {
    "log": {
      "is_write_index": true
    }
  }
}

```

1. making first index

```auto
log-2023.06.19-000001

```

---

<div class="post-metadata">

**Author:** ![pablo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/pablo/32/10363_2.png) [@pablo](https://forum.opensearch.org/u/pablo)\
**Post date:** [June 21, 2023, 2:22pm UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770/2 "2023-06-21T14:22:28Z")

</div>

> [@cucukaka](#):
>
> ```auto
> PUT /_template/ism_rollover_app
> {
> "index_patterns": "log*",
> "settings":{
> "index":{
> "opendistro.index_state_management.rollover_alias": "log"
> }
> }
> }
> 
> ```

Why did you use opendistro in OpenSearch? Also, this doesn’t fit the example provided in the mentioned documentation. As per documentation you must configure \_index\_template with rollover\_alias and not the \_template.

Please have a look at step 2.  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/b/b539d0169938d90e9881a27fdb38e632b194cbf6.png)

---

<div class="post-metadata">

**Author:** ![cucukaka](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cucukaka](https://forum.opensearch.org/u/cucukaka)\
**Post date:** [June 22, 2023, 12:32am UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770/3 "2023-06-22T00:32:00Z")

</div>

thank you @pablo I miss it…  
so I solved it like this

step1 → _skip step2_ → step 3(add “plugins.index\_state\_management.rollover\_alias”) → step 4

```auto
{
  "index_patterns": [
    "log*"
  ],
  "template": {
    "settings": {
      "index.number_of_shards": "3",
      "index.number_of_replicas": "1",
      "plugins.index_state_management.rollover_alias": "log"
    },
    "aliases": {
      "log": {}
    }
  },
  "composed_of": [],
  "priority": "0",
  "_meta": {
    "flow": "simple"
  },
  "name": "log"
}

```

---

<div class="post-metadata">

**Author:** ![cucukaka](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@cucukaka](https://forum.opensearch.org/u/cucukaka)\
**Post date:** [June 23, 2023, 2:14am UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770/4 "2023-06-23T02:14:45Z")

</div>

@pablo  
After editting yesterday, I thought fixed it.  
But today, I found another error

```auto
{ "cause": "Rollover alias [log] can point to multiple indices, found duplicated alias [[log]] in index template [log]", "message": "Failed to rollover index [index=log-2023.06.22-000001]" }

```

Is there another solution?

---

<div class="post-metadata">

**Author:** ![pablo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/pablo/32/10363_2.png) [@pablo](https://forum.opensearch.org/u/pablo)\
**Post date:** [June 23, 2023, 7:03pm UTC](https://forum.opensearch.org/t/how-do-i-apply-policy-to-index/14770/5 "2023-06-23T19:03:34Z")

</div>

@cucukaka Did you remove the old alias?

> [@cucukaka](#):
>
> ```auto
> PUT /_template/ism_rollover_app
> {
> "index_patterns": "log*",
> "settings":{
> "index":{
> "opendistro.index_state_management.rollover_alias": "log"
> }
> }
> }
> 
> ```
