# Dynamic Templates, Faceted Search, and path\_match

**URL:** <https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937>\
**Category:** Elasticsearch\
**Created:** [September 5, 2012, 5:42pm UTC](https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937 "2012-09-05T17:42:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greg_brown/32/1373_2.png) [@Greg\_Brown](https://discuss.elastic.co/u/Greg_Brown)\
**Post date:** [September 5, 2012, 5:42pm UTC](https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937/1 "2012-09-05T17:42:49Z")

</div>

I've tried a dozen variations to get this to work, so clearly there is  
something I don't understand.

I'm trying to dynamically create a field on an object with both an analyzed  
version of the field and a non-analyzed one so that the faceted results can  
return individual terms or the whole field.

eg. meta.byline : "Greg Brown" and meta\_raw.byline : "Greg Brown"; Result  
of the meta\_raw.byline facet should be "Greg Brown" while meta.byline  
should have two terms: "greg" and "brown"

Here's my latest attempt: [https://gist.github.com/3640532](https://gist.github.com/3640532)

Maybe I'm not using the path\_match on the dynamic template correctly? Also,  
I feel like the '"index" : "not\_analyzed"' on the meta\_raw object mapping  
should get inherited by sub-fields, but that doesn't seem to be what  
happens.

Bonus points for a way to use the multi\_field type mapping to make  
meta.byline and meta.byline.raw work. I decided to just try and get the  
simple solution to work first.

Thanks for the help.  
-Greg

--

---

<div class="post-metadata">

**Author:** ![Greg\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greg_brown/32/1373_2.png) [@Greg\_Brown](https://discuss.elastic.co/u/Greg_Brown)\
**Post date:** [September 5, 2012, 8:00pm UTC](https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937/2 "2012-09-05T20:00:52Z")

</div>

Figured out my own problem. Defining the meta and meta\_raw fields as  
objects seemed to override the dynamic template. Not sure if this is  
intended behavior.

Working version: [Working ElasticSearch dynamic template · GitHub](https://gist.github.com/3643513)

Still can't get the multi\_field to work: [gist:3643618 · GitHub](https://gist.github.com/3643618)

-Greg

On Wed, Sep 5, 2012 at 11:42 AM, Greg Brown [gbrown5878@gmail.com](mailto:gbrown5878@gmail.com) wrote:

> I've tried a dozen variations to get this to work, so clearly there is  
> something I don't understand.
> 
> I'm trying to dynamically create a field on an object with both an  
> analyzed version of the field and a non-analyzed one so that the faceted  
> results can return individual terms or the whole field.
> 
> eg. meta.byline : "Greg Brown" and meta\_raw.byline : "Greg Brown"; Result  
> of the meta\_raw.byline facet should be "Greg Brown" while meta.byline  
> should have two terms: "greg" and "brown"
> 
> Here's my latest attempt: [ElasticSearch Faceted Search and Dynamic Mapping/Templates · GitHub](https://gist.github.com/3640532)
> 
> Maybe I'm not using the path\_match on the dynamic template correctly?  
> Also, I feel like the '"index" : "not\_analyzed"' on the meta\_raw object  
> mapping should get inherited by sub-fields, but that doesn't seem to be  
> what happens.
> 
> Bonus points for a way to use the multi\_field type mapping to make  
> meta.byline and meta.byline.raw work. I decided to just try and get the  
> simple solution to work first.
> 
> Thanks for the help.  
> -Greg
> 
> --

--

---

<div class="post-metadata">

**Author:** ![amos\_wood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amos_wood/32/1880_2.png) [@amos\_wood](https://discuss.elastic.co/u/amos_wood)\
**Post date:** [September 6, 2012, 12:09pm UTC](https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937/3 "2012-09-06T12:09:00Z")

</div>

I haven't had any success using the "path\_match" option either. Instead, I  
use the "match" option which works fine which matches only on the field  
name and not on the path. If that isn't strict enough, then I define each  
object's mapping explicitly. To fix your dynamic\_templates section for the  
multi\_field,

change

"path\_match" : "_meta._"

to

"match" : "byline"

On Wednesday, September 5, 2012 3:00:55 PM UTC-5, Greg Brown wrote:

> Figured out my own problem. Defining the meta and meta\_raw fields as  
> objects seemed to override the dynamic template. Not sure if this is  
> intended behavior.
> 
> Working version: [Working ElasticSearch dynamic template · GitHub](https://gist.github.com/3643513)
> 
> Still can't get the multi\_field to work: [gist:3643618 · GitHub](https://gist.github.com/3643618)
> 
> -Greg
> 
> On Wed, Sep 5, 2012 at 11:42 AM, Greg Brown \<[gbrow...@gmail.com](mailto:gbrow...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I've tried a dozen variations to get this to work, so clearly there is  
> > something I don't understand.
> > 
> > I'm trying to dynamically create a field on an object with both an  
> > analyzed version of the field and a non-analyzed one so that the faceted  
> > results can return individual terms or the whole field.
> > 
> > eg. meta.byline : "Greg Brown" and meta\_raw.byline : "Greg Brown"; Result  
> > of the meta\_raw.byline facet should be "Greg Brown" while meta.byline  
> > should have two terms: "greg" and "brown"
> > 
> > Here's my latest attempt: [ElasticSearch Faceted Search and Dynamic Mapping/Templates · GitHub](https://gist.github.com/3640532)
> > 
> > Maybe I'm not using the path\_match on the dynamic template correctly?  
> > Also, I feel like the '"index" : "not\_analyzed"' on the meta\_raw object  
> > mapping should get inherited by sub-fields, but that doesn't seem to be  
> > what happens.
> > 
> > Bonus points for a way to use the multi\_field type mapping to make  
> > meta.byline and meta.byline.raw work. I decided to just try and get the  
> > simple solution to work first.
> > 
> > Thanks for the help.  
> > -Greg
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:13am UTC](https://discuss.elastic.co/t/dynamic-templates-faceted-search-and-path-match/8937/4 "2017-07-06T03:13:56Z")

</div>


