Create initial index using aliases with ISM

I’m new to ISM, and wondering how do use ISM to create the initial index using an ISM policy.
Note I cannot create the index manually, since we are creating different index groups on the fly.
My goal is that when I write in my backend code that uses the alias for writing, the initial backing index will be created automatically. But I can’t get it to work.

This is the backend code:

client.index({
  index: 'my_alias',
 body: {
   prop: 'joe'
 })

I created the following policy and index template:

{
  "policy": {
    "default_state": "open",
    "ism_template": {
      "index_patterns": ["ppp*"],
      "priority": 100
    },
    "states": [ {
      "name": "open"
    }]
  }
}

PUT _template/ppp_template
{
  "index_patterns": [ "ppp*"], 
  "aliases": {
    "my_alias": {
    }
  }
}

But when I try to index a document to my_alias I get the following error:

{
“error” : {
“root_cause” : [
{
“type” : “illegal_state_exception”,
“reason” : “index, alias, and data stream names need to be unique, but the following duplicates were found [pppx (alias of [pppx/StEAdDnHRButkRXs-otvqA]) conflicts with index]”
}
],
“type” : “illegal_state_exception”,
“reason” : “index, alias, and data stream names need to be unique, but the following duplicates were found [pppx (alias of [pppx/StEAdDnHRButkRXs-otvqA]) conflicts with index]”
},
“status” : 500
}

What am I doing wrong?

I don’t believe you can use an alias if there is no actual alias to use yet (even if you specified it in a template, it doesn’t mean a concrete one exists that maps to an index). In your backend code can you first create an index that starts with ppp which will then get created and have the alias attached and the ISM policy applied and then once that index creation is successful start using the alias?