Not_analyzed as default for string type for multiple indices

Hi,

I collect performance data into ES and my indices are named in a form
"prefix_" in order to delete old data efficiently. For all
those indices and all types within them, I'd like to have string fields
not_analyzed and exact matched in searches. My issue is that indices are
created by first index request to them, so I cannot easily preset the
analyzers via mappers. I've tried to use global templates as:

POST http://localhost:9200/_template/t2

{
"template" : "z*",
"mapping" : {
"type" : "string",
"index" : "not_analyzed"
}
}

which seems to be taken into consideration when the index is created, but
still, for filtered query like:

{
"query": {
"filtered" : {
"filter" : {
"bool" : {
"must" : [
{"term" : {"path4" : "BASE"}},
{"term" : {"path3" : "vm-609"}}
]
}
}
}
}
}

I'm not getting any document while for query_string query like:
{
"query" : {
"query_string" : {
"query" : "path3:"vm-609" AND path4:"BASE""
}
}
}

I'm getting the expected results.

So my question is, how to disable string field analysis in order to be able
to use filtered queries for all in future created indices whose names
follow my pattern "prefix_"

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0ae751d3-fc67-42a1-8130-d8116398b7ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

This did the trick for me:

POST http://localhost:9200/_template/t2

{
"template" : "z*",
"mappings" : {
"default" : {
"_all" : {"enabled" : false},
"dynamic_templates": [
{ "string_match": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index" : "not_analyzed"
}
}}
]

    }
}

}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b9a01536-c028-4402-b86a-c38dcec09fd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1 Like