Dynamic_templates and match_mapping_type


(dawi) #1

Hi,

I have introduced a default-mapping.json to store all fields of type
string in a normal and a reversed version. That works great so far!

My problem is that now I cannot search for date fields anymore. It
seems that the dynamic
template applies to date fields as well, although I've
set "match_mapping_type" to "string".
Elasticsearch says: Field [...] is not a numeric type.

A possible solution would be to use field prefixes and configure
the dynamic template to only apply to fields that match "string_*".
e.g. document.string_name, document.string_email, document.date_lastlogin,
...

But I am not sure if this is the best solution.

{

"defaultmapping" : {
    "dynamic_templates" : [
        {
            "string_template" : {
                "match" : "*",
                "match_mapping_type" : "string",
                "mapping" : {
                    "type" : "multi_field",
                    "fields" : {
                        "{name}" : {"type": "{dynamic_type}", "index" 

: "analyzed", "store" : "yes"},
"reverse" : {"type": "{dynamic_type}", "index"
: "analyzed", "index_analyzer": "reverseanalyzer", "store" : "yes"}
}
}
}
}
]
}
}

Any hints greatly appreciated.

Regards, Daniel


(Shay Banon) #2

Heya,

This has been fixed in 0.18 branch and upcoming 0.18.3 (which will be out
this week).

-shay.banon

On Fri, Nov 11, 2011 at 7:02 PM, dawi d.wilmer.1980@googlemail.com wrote:

Hi,

I have introduced a default-mapping.json to store all fields of type
string in a normal and a reversed version. That works great so far!

My problem is that now I cannot search for date fields anymore. It
seems that the dynamic
template applies to date fields as well, although I've
set "match_mapping_type" to "string".
Elasticsearch says: Field [...] is not a numeric type.

A possible solution would be to use field prefixes and configure
the dynamic template to only apply to fields that match "string_*".
e.g. document.string_name, document.string_email, document.date_lastlogin,
...

But I am not sure if this is the best solution.

{

"defaultmapping" : {
    "dynamic_templates" : [
        {
            "string_template" : {
                "match" : "*",
                "match_mapping_type" : "string",
                "mapping" : {
                    "type" : "multi_field",
                    "fields" : {
                        "{name}" : {"type": "{dynamic_type}", "index"

: "analyzed", "store" : "yes"},
"reverse" : {"type": "{dynamic_type}",
"index" : "analyzed", "index_analyzer": "reverseanalyzer", "store" : "yes"}
}
}
}
}
]
}
}

Any hints greatly appreciated.

Regards, Daniel


(dawi) #3

Ok, thanks for this info. :slight_smile:


(dawi) #4

Hi Shay,

I just tested with the latest repository version 0.19.0 SNAPSHOT which
includes commit:

*Mapping: Improve applying guessed types on dynamic templates, closes #1446.
*
But the problem still exists.

If I don't use this dynamic_template I am able to search for strings and
dates.
If I use the given dynamic mapping above, then i can only search for
strings but for dates it says: Field [...] is not a numeric type.

If you need more information about this or maybe some logs, please let me
know.

Regards,
Daniel


(dawi) #5

Hi Shay,

my mistake.

I've tested with the actual 0.19.0 SNAPSHOT and everything works as
expected!

Regards,
Daniel


(system) #6