# Mapping for objects with an arbitrary amount of properties

**URL:** <https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626>\
**Category:** Elasticsearch\
**Created:** [November 28, 2013, 11:57am UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626 "2013-11-28T11:57:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hereandnow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hereandnow/32/1945_2.png) [@hereandnow](https://discuss.elastic.co/u/hereandnow)\
**Post date:** [November 28, 2013, 11:57am UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626/1 "2013-11-28T11:57:01Z")

</div>

i have a given document:

{  
"foo": {}  
}

where `foo` can have an arbitrary amount of properties. lets assume i will  
import millions of documents into my index, in which each of `foo`'s  
properties do have other values.

that means my mapping which will be built dynamically will grow enormous.  
is there any kind of way where i can tell elasticsearch something like

_take everything you have in `foo` and just accept it as it is (or  
stringify `foo`) without having a resulting million-lines-mapping???_

or do i have to care by myself, before indexing documents?

if so, there a 2 solutions i think

1. JSON-Stringify

JSON.stringify(obj.foo)

1. map every property in `foo` into key/value pairs, and create an array of  
objects:

// object  
{  
"foo": [  
{"key": "bar1", "value": "bar1's value"},  
{"key": "bar2", "value": "bar2's value"}  
]  
}

// resulting mapping  
{  
"type": {  
"properties": {  
"foo": {  
"properties": {  
"key": {  
"type": "string"  
},  
"value": {  
"type": "string"  
}  
}  
}  
}  
}  
}

would you prefer then solution 1 or 2, and why?

appreciate your help!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1207c3c0-3fba-4b6e-9cfc-b501afca1614%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1207c3c0-3fba-4b6e-9cfc-b501afca1614%40googlegroups.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:** [November 28, 2013, 9:31pm UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626/2 "2013-11-28T21:31:15Z")

</div>

Not sure I understood completely the use case. Having real data could help.

That said, if you do solution 2 I think you will need to use nested documents to index sub documents in foo.  
Nested docs are actual Lucene docs. So indexing  
{  
"foo": [  
{"key": "bar1", "value": "bar1's value"},  
{"key": "bar2", "value": "bar2's value"}  
]  
}

will result in 3 docs (the main one and one for each key/value pair).

Nested documents are fine but complicate then a little queries.

For example 1, could you illustrate how your document will look like?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 28 novembre 2013 at 12:57:04, hereandnow ([hereandnow78@googlemail.com](mailto:hereandnow78@googlemail.com)) a écrit:

i have a given document:

{  
"foo": {}  
}

where `foo` can have an arbitrary amount of properties. lets assume i will import millions of documents into my index, in which each of `foo`'s properties do have other values.

that means my mapping which will be built dynamically will grow enormous. is there any kind of way where i can tell elasticsearch something like

take everything you have in `foo` and just accept it as it is (or stringify `foo`) without having a resulting million-lines-mapping???

or do i have to care by myself, before indexing documents?

if so, there a 2 solutions i think

1. JSON-Stringify

JSON.stringify(obj.foo)

1. map every property in `foo` into key/value pairs, and create an array of objects:

// object  
{  
"foo": [  
{"key": "bar1", "value": "bar1's value"},  
{"key": "bar2", "value": "bar2's value"}  
]  
}

// resulting mapping  
{  
"type": {  
"properties": {  
"foo": {  
"properties": {  
"key": {  
"type": "string"  
},  
"value": {  
"type": "string"  
}  
}  
}  
}  
}  
}

would you prefer then solution 1 or 2, and why?

## appreciate your help!

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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1207c3c0-3fba-4b6e-9cfc-b501afca1614%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1207c3c0-3fba-4b6e-9cfc-b501afca1614%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.5297b623.26f324ba.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5297b623.26f324ba.3e14%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![hereandnow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hereandnow/32/1945_2.png) [@hereandnow](https://discuss.elastic.co/u/hereandnow)\
**Post date:** [November 29, 2013, 9:28am UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626/3 "2013-11-29T09:28:08Z")

</div>

thanks for your answer. i found a solution for this. i dont need to search  
on 'foo' so i can just disable the field, to prevent bloating of my mapping

"foo": {  
"type": "object",  
"enabled": false  
}

Am Donnerstag, 28. November 2013 12:57:01 UTC+1 schrieb hereandnow:

> i have a given document:
> 
> {  
> "foo": {}  
> }
> 
> where `foo` can have an arbitrary amount of properties. lets assume i will  
> import millions of documents into my index, in which each of `foo`'s  
> properties do have other values.
> 
> that means my mapping which will be built dynamically will grow enormous.  
> is there any kind of way where i can tell elasticsearch something like
> 
> _take everything you have in `foo` and just accept it as it is (or  
> stringify `foo`) without having a resulting million-lines-mapping???_
> 
> or do i have to care by myself, before indexing documents?
> 
> if so, there a 2 solutions i think
> 
> 1. JSON-Stringify
> 
> JSON.stringify(obj.foo)
> 
> 1. map every property in `foo` into key/value pairs, and create an array  
> of objects:
> 
> // object  
> {  
> "foo": [  
> {"key": "bar1", "value": "bar1's value"},  
> {"key": "bar2", "value": "bar2's value"}  
> ]  
> }
> 
> // resulting mapping  
> {  
> "type": {  
> "properties": {  
> "foo": {  
> "properties": {  
> "key": {  
> "type": "string"  
> },  
> "value": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> would you prefer then solution 1 or 2, and why?
> 
> appreciate your help!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3df422a7-37d2-43d5-bb96-75865fe67740%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3df422a7-37d2-43d5-bb96-75865fe67740%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![hereandnow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hereandnow/32/1945_2.png) [@hereandnow](https://discuss.elastic.co/u/hereandnow)\
**Post date:** [November 29, 2013, 9:29am UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626/4 "2013-11-29T09:29:01Z")

</div>

thanks for your answer. i found a solution for this. i dont need to search  
on 'foo' so i can just disable the field, to prevent bloating of my mapping

"foo": {  
"type": "object",  
"enabled": false  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a008f1a0-90a2-4531-a1e9-bd7ee000eaf1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a008f1a0-90a2-4531-a1e9-bd7ee000eaf1%40googlegroups.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:04am UTC](https://discuss.elastic.co/t/mapping-for-objects-with-an-arbitrary-amount-of-properties/14626/5 "2017-07-06T02:04:12Z")

</div>


