Mapping: setup type by path


(Eugene Prokopiev) #1

Hi,

I tried to setup explicit mapping by path:

PUT x
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "relevance": {
      "dynamic_templates": [
        {
          "relevance": {
            "path_match": "*.relevance",
            "mapping": {
              "type": "text"
            }
          }
        }
      ]
    }
  }
}

But no success:

PUT x/x/0
{
  "name": "X",
  "metrics" : {
    "relevance" : 0
  }
}

GET /x/_mapping

{
  "x": {
    "mappings": {
      "relevance": {
        "dynamic_templates": [
          {
            "relevance": {
              "path_match": "*.relevance",
              "mapping": {
                "type": "text"
              }
            }
          }
        ]
      },
      "x": {
        "properties": {
          "metrics": {
            "properties": {
              "relevance": {
                "type": "long"
              }
            }
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

Som why I see relevance field as long?


(Jun Ohtani) #2

Your dynamic_templates affect under relevance type data only.
You index data as x/x/0 that this means "x" index and "x" type and "0" id.
And your relevance field is long in JSON, elasticsearch decide field type from JSON type.

If you want to use "dynamic_templates" to all types, you can use _default_ mapping.


(system) #3

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