elasticsearch/elasticsearch — pull request #3093 by javanna (2013-05-25 23:49:18+00:00)
Title: Add {path} keyword to dynamic templates to be replaced with the full path of the field

For a project I've been working on I have json documents that contain multiple inner objects, where the content of the inner objects can contain similar fields, as in the following example:

```
{
"inner1" : {
"title" : "title inner1"
},
"inner2" : {
"title" : "title inner2"
}
}
```

I want to keep all the titles in separate fields with the described structured, but at the same time I want to have a catch all field that contains all the titles, possibly as a top level field called title. I achieved this with a multi_field using the "just_name" type like this:

```
"inner1" : {
"type" : "object",
"properties" : {
"title" : {
"type" : "multi_field",
"path" : "just_name",
"fields" : {
"title" : {"type":"string"},
"inner1.title" : {"type":"string"}
}
}
}
}
```

The bad thing is that I would have to repeat in the mapping the same multi_field for every level where I want to take the title from, that's why I thought to use dynamic templates. Unfortunately the fact that the second field in the multi_field contains the path is a problem and not supported through a placeholder like {name} or {dynamic_type}.

The pull request adds the support for a new {path} placeholder that makes it possible to do the following:

```
"template":{
"path_match":"*.title",
"mapping":{
"type": "multi_field",
"path":"just_name",
"fields":{
"{name}": {"type": "{dynamic_type}"},
"{path}": {"type": "{dynamic_type}"}
}
}
}
```

This way with a single dynamic template I can achieve what I want for multiple fields taken from multiple levels in the json tree.