Creating index template


(imad) #1

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.


(russK) #2

What do you see when you run:

curl localhost:9200/_template?pretty


(imad) #3

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": {}
}
}


(imad) #4

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


(Mark Walkom) #5

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


(imad) #6

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.


(Mark Walkom) #7

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


(system) #8