Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch dynamic mapping compared to Solr dynamic field

In Solr I can define a dynamic field and tie it to a particular data type. In the following example all fields in an indexed document ending with "dt" will be indexed as a long. <dynamicField name="*_dt" stored="true" indexed="true" type="long" multiValued="true"/>

In ElasticSearch, knowing the name of the field, I can use the "properties" sub-node in "mappings" to index a field to a particular type. "properties": { "msh_datetimeofmessage_hl7_dt": { "type": "date", "format": "YYYYMMddHHmmss" },

I tried the following and attempted using a template, unsuccessfully. "properties": { "*_dt": { "type": "date", "format": "YYYYMMddHHmmss" },

Does ElasticSearch provide the same functionality as Solr as described above?

Thanks in advance.

like image 809
user481779 Avatar asked Oct 19 '22 15:10

user481779


1 Answers

I think you may be looking for functionality provided by dynamic templates. Unless I am mistaken, your mapping would look something like this (mostly borrowed from the linked page).

PUT /my_index
{
"mappings": {
    "my_type": {
        "dynamic_templates": [
            { "my_date_template": {
                  "match":              "*_dt", 
                  "mapping": {
                      "type":           "date",
                      "format": "YYYYMMDDHHmmss"
                  }
            }}
        ]
}}}
like image 69
fabianvf Avatar answered Oct 30 '22 21:10

fabianvf