# Mapping for nested object with dynamic keys, uniform values

**URL:** <https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919>\
**Category:** Elasticsearch\
**Created:** [May 11, 2013, 2:08am UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919 "2013-05-11T02:08:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_C](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Carl\_C](https://discuss.elastic.co/u/Carl_C)\
**Post date:** [May 11, 2013, 2:08am UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919/1 "2013-05-11T02:08:58Z")

</div>

Hi all,

I have a specific question about mapping definitions that I think will help  
with my understanding of mapping more generally. Suppose I have a document  
that looks something like the following:

{  
"doc" : {  
"nested\_map": {  
"key1": { /\* obj1 _/ },  
"key2": { /_ obj2 \*/ },  
...  
},  
// Other fields...  
}  
}

Suppose further that the key space for the nested\_map is dynamic /  
potentially unbounded (and isn't necessarily "nicely" named, such as  
matchable by a regex), but the corresponding values all have the same  
structure. I'd like to provide a mapping definition that tightly controls  
the interpretation of those values (eg, obj1, obj2). How do I do so, given  
that the actual field names for those objects are unknown?

Intuitively, I want to say something along the lines of "all fields of any  
name in this (non-root) object should get the same object mapping." What is  
the best way to express that?

Thanks very much,  
Carl

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2013, 2:34am UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919/2 "2013-05-11T02:34:30Z")

</div>

Not sure I fully understand your use case.

May be default mapping is the feature you are looking for?  
See [http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping/](http://www.elasticsearch.org/guide/reference/mapping/dynamic-mapping/)

Does it help? If not, could you send some doc samples?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 11 mai 2013 à 04:08, Carl C [carl@siftscience.com](mailto:carl@siftscience.com) a écrit :

Hi all,

I have a specific question about mapping definitions that I think will help with my understanding of mapping more generally. Suppose I have a document that looks something like the following:

{  
"doc" : {  
"nested\_map": {  
"key1": { /\* obj1 _/ },  
"key2": { /_ obj2 \*/ },  
...  
},  
// Other fields...  
}  
}

Suppose further that the key space for the nested\_map is dynamic / potentially unbounded (and isn't necessarily "nicely" named, such as matchable by a regex), but the corresponding values all have the same structure. I'd like to provide a mapping definition that tightly controls the interpretation of those values (eg, obj1, obj2). How do I do so, given that the actual field names for those objects are unknown?

Intuitively, I want to say something along the lines of "all fields of any name in this (non-root) object should get the same object mapping." What is the best way to express that?

## Thanks very much, Carl

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 11, 2013, 11:56pm UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919/3 "2013-05-11T23:56:02Z")

</div>

Not sure exactly how complicated your document structure is, but you can  
start of by having a dynamic template where the path\_match field is the  
name of the nested object: "path\_match": "nested\_map". You can then break  
things down by type.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--  
Ivan

On Fri, May 10, 2013 at 7:08 PM, Carl C [carl@siftscience.com](mailto:carl@siftscience.com) wrote:

> Hi all,
> 
> I have a specific question about mapping definitions that I think will  
> help with my understanding of mapping more generally. Suppose I have a  
> document that looks something like the following:
> 
> {  
> "doc" : {  
> "nested\_map": {  
> "key1": { /\* obj1 _/ },  
> "key2": { /_ obj2 \*/ },  
> ...  
> },  
> // Other fields...  
> }  
> }
> 
> Suppose further that the key space for the nested\_map is dynamic /  
> potentially unbounded (and isn't necessarily "nicely" named, such as  
> matchable by a regex), but the corresponding values all have the same  
> structure. I'd like to provide a mapping definition that tightly controls  
> the interpretation of those values (eg, obj1, obj2). How do I do so, given  
> that the actual field names for those objects are unknown?
> 
> Intuitively, I want to say something along the lines of "all fields of any  
> name in this (non-root) object should get the same object mapping." What is  
> the best way to express that?
> 
> Thanks very much,  
> Carl
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![john\_4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_4/32/2230_2.png) [@john\_4](https://discuss.elastic.co/u/john_4)\
**Post date:** [July 10, 2013, 9:54pm UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919/4 "2013-07-10T21:54:07Z")

</div>

I have a similar problem. I have json documents coming out of a couchdb  
which are composed of varying layers of nesting, with variable keys, but  
static structure. I know whenever it is an array it will be an array of  
objects, whenever elastic identifies something as 'dynamic', I want these  
to be set instead to nested.

-John

On Saturday, May 11, 2013 4:56:02 PM UTC-7, Ivan Brusic wrote:

> Not sure exactly how complicated your document structure is, but you can  
> start of by having a dynamic template where the path\_match field is the  
> name of the nested object: "path\_match": "nested\_map". You can then break  
> things down by type.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type/)
> 
> --  
> Ivan
> 
> On Fri, May 10, 2013 at 7:08 PM, Carl C \<[ca...@siftscience.com](mailto:ca...@siftscience.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi all,
> > 
> > I have a specific question about mapping definitions that I think will  
> > help with my understanding of mapping more generally. Suppose I have a  
> > document that looks something like the following:
> > 
> > {  
> > "doc" : {  
> > "nested\_map": {  
> > "key1": { /\* obj1 _/ },  
> > "key2": { /_ obj2 \*/ },  
> > ...  
> > },  
> > // Other fields...  
> > }  
> > }
> > 
> > Suppose further that the key space for the nested\_map is dynamic /  
> > potentially unbounded (and isn't necessarily "nicely" named, such as  
> > matchable by a regex), but the corresponding values all have the same  
> > structure. I'd like to provide a mapping definition that tightly controls  
> > the interpretation of those values (eg, obj1, obj2). How do I do so, given  
> > that the actual field names for those objects are unknown?
> > 
> > Intuitively, I want to say something along the lines of "all fields of  
> > any name in this (non-root) object should get the same object mapping."  
> > What is the best way to express that?
> > 
> > Thanks very much,  
> > Carl
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:27am UTC](https://discuss.elastic.co/t/mapping-for-nested-object-with-dynamic-keys-uniform-values/11919/5 "2017-07-06T02:27:04Z")

</div>


