-
Notifications
You must be signed in to change notification settings - Fork 24.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic template with match_mapping_type ignored when there's a match "*" after it #2401
Comments
Unfortunately, it seems the dynamic template list in org.elasticsearch.index.mapper.object.RootObjectMapper is derived from a map, fetched as Map<String,Object> from the given JSON source. So the keys in the map are not guaranteed to be ordered sequentially. I guess, internally, the entry "everything" is ordered before the entry "strings". My suggestion is to add a positional attribute ("position") to the dynamic_templates entries so ES can order them more reliably according to the users preference. Patch wanted? |
Another cause may be that equals() and hashcode() methods in org.elasticsearch.index.mapper.object.DynamicTemplate do not work as expected. |
It occurs to me that my original example is a bit bogus anyway -- since the omit_norms and omit_term_freq_and_positions are only valid for string types anyway. But the general point still stands... |
Hi, this one is tricky... . The order is actually properly maintained of the dynamic templates, so thats not the problem (the array in the dynamic templates denotes the order, and we respect that). The problem is with how we resolve dynamic templates, specifically, with The reason for this behavior is actually down to JSON and binary values. Because binary values in json are strings, trying to auto detect a date for example by trying to convert it to string ends up screwing up the internal parser binary value (I need to check if thats the case still). So we first need to try and match on name without actually knowing the type, and then match on the type... What you see happens because in the initial match on name (without type), it ends up actually matching on the catch all This one requires some thinking, not an easy one to solve... |
Is there any plan to fix this? On recent ElasticSearch version it still happens. Is there any other way to provide specific dynamic mapping template for strings and another template for all other types? |
I've just run into this as well. I want strings within a subpath to be analyzed with a specific analyzer, and for all other types in the same subpath to be not_analyzed (but with some other changes for which I need a mapping defined -- for example, a set index_name). It seems because of this behavior I may need to put my strings into a different subpath. I was hoping to avoid making structure choices in my documents just so I can map it correctly. |
Wondering if an |
Recently came across this. The following is the use case: https://gist.github.com/ppf2/6da223f9517ddc0e9465 In this case, what appears to work (Test 2 in the gist) is if I add |
This is a sweet workaround. It appears working for me. thanks |
Given @ppf2 's workaround in #2401 (comment) it seems that we just need to default |
+1 The workaround of adding PUT /_template/log_template
{
"template": "log*",
"mappings": {
"_default_": {
"dynamic_templates": [
{
"timestamp": {
"match": "@timestamp",
"match_mapping_type": "*",
"mapping": {
"type": "date",
"index": "not_analyzed",
"doc_values": true
}
}
},
{
"string_multifield": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"doc_values": true
}
}
}
}
},
{
"catch_all": {
"match": "*",
"match_mapping_type": "*",
"mapping": {
"index": "not_analyzed",
"doc_values": true
}
}
}
]
}
}
} |
@kimchy can you expand on what you mean here:
This patch:
seems to work fine with binary strings, eg:
returns:
and
returns:
And to update the original example, this seems to work correctly:
returns:
|
there's a "bug" in ES (elastic/elasticsearch#2401) that not doing so means that gets tested first
there's a "bug" in ES (elastic/elasticsearch#2401) that not doing so means that gets tested first
Closed by #18638 |
I have the following dynamic mappings set up in default-mapping.json:
If I understand this page correctly (at the very bottom):
http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html
the first mapping that matches will be applied -- i.e. "everything" should only be applied to fields that don't match "strings".
However, this isn't what I see (in 0.19.8 anyway) -- no matter which order I put the mappings in, all fields have "everything" applied, including string fields.
(By the way, "lowercase" is a simple custom analayzer with a keyword tokenizer and lowercase token filter.)
The text was updated successfully, but these errors were encountered: