How to select an index template from a logstash pipeline?

I have made an index template with the following index pattern:

POST _template/myindex-template
{
 "index_patterns": [
   "myindex-*"
 ],
 "settings": { .....

for what I understand just by using the index pattern in the name of the index, the index template will be applied:

output {
        elasticsearch { hosts => ["elastic_ip"] index => "myindex-cpu-%{+YYYY.MM}" 
}

but it doesnt seems to work, do I need to specify something else?

You probably need to explicitly set this one to no - https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-manage_template

That way your template will be used.