Creating index template

I am trying to create an index template so that all indices created afterwards have same mapping. Here is how I am creating it:

curl -XPUT localhost:9200/_template/vw_index_template -d ' {
"template" : "*_index",
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"id_prkey_template" : {
"properties" : {
"_id" : {"type" : "string", "index": "not_analyzed"},
"prkey" : {"type" : "string", "index": "analyzed"}
}
}
}
}

but indices that I create afterwards still have default mapping where they should only have two fields in mapping.
Will appreciate any help.

Thanks.

What do you see when you run:

curl localhost:9200/_template?pretty

When I run curl localhost:9200/_template?pretty, I see this:

{
"vw_index_template": {
"order": 0,
"template": "*_index",
"settings": {
"index.number_of_shards": "1"
},
"mappings": {
"id_prkey_template": {
"_source": {
"enabled": false
},
"properties": {
"prkey": {
"index": "analyzed",
"type": "string"
},
"_id": {
"index": "not_analyzed",
"type": "string"
}
}
}
},
"aliases": {}
}
}

still waiting to resolve this.. would appreciate any help, thx.

What do you mean by that?
I just replicated what you posted and it worked fine.

May be I am missing something then. So all I did is, I ran the above curl command to create the template, then I created my river with my index index as follows:

PUT _river/role_index/_meta
{
"type" : "couchdb", "couchdb" : { "host" : "localhost", "port" : 5984, "db" : "roles", "filter" : null },
"index" : { "index" : "role_index", "type" : "roles", "bulk_size" : "100", "bulk_timeout" : "10ms" }}

And when I search for my index 'role_index', I see all fields instead of just _id and prkey fields. Which means template is not getting applied to index that I create afterwards.

Here is how I do the search:
GET role_index/_search?pretty=true

Will appreciate any help.
Thanks.

Ok, that's expected.
With your template you aren't telling ES to only process these fields, you are saying you are only defining what these fields should be. It'll still index the rest of them and just dynamically figure out what they should be (string, int etc). Check your logs and you should see mention of dynamic mapping updates for that index.

Also, rivers are deprecated, you should look for other functionality such as https://www.elastic.co/guide/en/logstash/current/plugins-inputs-couchdb_changes.html