Dynamic template for complex types

Hello,

is it possible to have a complex type (like a geopoint) dinamically recognized using the dynamic_templates section of a template/index mapping?

Sort of:

PUT test_loc/doc/1
{
  "position" : [-64, -19.4]
}

resulting in position field recognized as a geopoint, instead of float.

No it's not AFAIK. You should better detect on the field name in such a case.

Thank you for your answer, @dadoonet.
I tried what follows, but it doesn't seem to work as expected:

DELETE test-loc

PUT test-loc
{
  "mappings": {
    "doc": {
      "dynamic_templates": [
        {
          "geo_mapping_1": {
            "match_mapping_type": "string",
            "match": "*location",
            "mapping": {
              "type": "geopoint"
            } } }
      ] } }
}

GET test-loc

PUT test-loc/doc/1
{ "start_location" : { "lon" : 4.8995, "lat" : 52.3824 } }

GET test-loc

After the post of document 1 I get:

# GET test-loc
{
  "test-loc" : {
    "aliases" : { },
    "mappings" : {
      "_default_" : {
        "_all" : {
          "enabled" : false
        }
      },
      "doc" : {
        "_all" : {
          "enabled" : false
        },
        "dynamic_templates" : [
          {
            "geo_mapping_1" : {
              "match" : "*location",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "geopoint"
              }
            }
          }
        ],
        "properties" : {
          "start_location" : {
            "properties" : {
              "lat" : {
                "type" : "float"
              },
              "lon" : {
                "type" : "float"
              }      
       } } } }
    },
        . . .
    }
  }
}

So, apparently, I'm missing something: start_location property isn't correctly recognized as a geopoint.

I can statically create a geopoint property:

DELETE test-loc
PUT test-loc
{
  "mappings": {
    "doc": {
      "dynamic_templates": [
        {
          "geo_mapping_1": {
            "match_mapping_type": "string",
            "match": "*location",
            "mapping": {
              "type": "geopoint"
            }
          }
        }
      ],
      "properties" : {
          "dest_location": {
            "type" : "geo_point"
          }
      }
    }
  }
}

and the dest_location is correctly mapped when indexing the following document:

PUT test-loc/doc/2
{
  "dest_location" : { 
      "lon" : 4.8995,
      "lat" : 52.3824
  }
}

Is there a way to have the complex type correctly recognized and dinamically mapped to the desired property type?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.