# Best way to store variable number of key:value fields

**URL:** <https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167>\
**Category:** Elasticsearch\
**Created:** [April 24, 2014, 6:52am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167 "2014-04-24T06:52:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominic\_Gross](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dominic\_Gross](https://discuss.elastic.co/u/Dominic_Gross)\
**Post date:** [April 24, 2014, 6:52am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/1 "2014-04-24T06:52:20Z")

</div>

Hi,  
I want to index some Data, where each Document should have a variable  
number of fields.  
An example because I can't express myself very good this morning:

Apple  
Color: Green  
Flavor: Sour

Mobilephone  
Color: black  
Os: Android

My problem is, that "Apple" should not have the field Os and the  
Mobilephone shouldnt have the field Flavor in turn.

Im new to Elasticsearch, so maybe there is an easy answer for that.

--  
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/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [April 24, 2014, 6:59am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/2 "2014-04-24T06:59:13Z")

</div>

Hi Dominic,

It's not very clear to me what your question is. You want to reject Apple  
documents that have an OS field?

I guess you can either have Apples and Mobilephones in their own type. This  
will make it clear which fields belong to which type of document. And  
because ES has dynamic mappings enabled by default, you can always add new  
types of documents, or new fields to a current type:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

## Best regards Radu

Performance Monitoring \* Log Analytics \* Search Analytics  
Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

On Thu, Apr 24, 2014 at 9:52 AM, Dominic Gross [dvgrossd@gmail.com](mailto:dvgrossd@gmail.com) wrote:

> Hi,  
> I want to index some Data, where each Document should have a variable  
> number of fields.  
> An example because I can't express myself very good this morning:
> 
> Apple  
> Color: Green  
> Flavor: Sour
> 
> Mobilephone  
> Color: black  
> Os: Android
> 
> My problem is, that "Apple" should not have the field Os and the  
> Mobilephone shouldnt have the field Flavor in turn.
> 
> Im new to Elasticsearch, so maybe there is an easy answer for that.
> 
> --  
> 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/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/783ca00e-dbae-4ad2-955a-61c1af4ef080%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAHXA0\_0DSe%2BmrzZfykt42%2BFQ39EZ\_Rj-UOSQ7HaKKgCg9TPcNg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_0DSe%2BmrzZfykt42%2BFQ39EZ_Rj-UOSQ7HaKKgCg9TPcNg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dominic\_Gross](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dominic\_Gross](https://discuss.elastic.co/u/Dominic_Gross)\
**Post date:** [April 24, 2014, 7:08am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/3 "2014-04-24T07:08:35Z")

</div>

So I can just write the two Documents (Apple and Mobilephone) to the same  
Index (and the same Type?).

--  
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/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [April 24, 2014, 7:10am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/4 "2014-04-24T07:10:10Z")

</div>

You can do that, too, yes.

On Thu, Apr 24, 2014 at 10:08 AM, Dominic Gross [dvgrossd@gmail.com](mailto:dvgrossd@gmail.com) wrote:

> So I can just write the two Documents (Apple and Mobilephone) to the same  
> Index (and the same Type?).
> 
> --  
> 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/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Performance Monitoring \* Log Analytics \* Search Analytics  
Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

--  
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/CAHXA0\_12sbbqWyGzu0EXCpsXOBrdXMA72KQucA4GWoxJKN%2BQxA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_12sbbqWyGzu0EXCpsXOBrdXMA72KQucA4GWoxJKN%2BQxA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dominic\_Gross](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@Dominic\_Gross](https://discuss.elastic.co/u/Dominic_Gross)\
**Post date:** [April 24, 2014, 7:16am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/5 "2014-04-24T07:16:01Z")

</div>

Thats awesome, thank you for your help!

Am Donnerstag, 24. April 2014 09:10:10 UTC+2 schrieb Radu Gheorghe:

> You can do that, too, yes.
> 
> On Thu, Apr 24, 2014 at 10:08 AM, Dominic Gross \<[dvgr...@gmail.com](mailto:dvgr...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > So I can just write the two Documents (Apple and Mobilephone) to the same  
> > Index (and the same Type?).
> > 
> > --  
> > 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:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4446198-a1b1-4d72-876f-711df91aa5b9%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Performance Monitoring \* Log Analytics \* Search Analytics  
> Solr & Elasticsearch Support \* [http://sematext.com/](http://sematext.com/)

--  
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/487a1a28-1bec-4318-8f0b-a321429cbe08%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/487a1a28-1bec-4318-8f0b-a321429cbe08%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [April 24, 2014, 8:02am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/6 "2014-04-24T08:02:39Z")

</div>

You're welcome 🙂

On Thu, Apr 24, 2014 at 10:16 AM, Dominic Gross [dvgrossd@gmail.com](mailto:dvgrossd@gmail.com) wrote:

> Thats awesome, thank you for your help!
> 
> Am Donnerstag, 24. April 2014 09:10:10 UTC+2 schrieb Radu Gheorghe:
> 
> > You can do that, too, yes.
> > 
> > On Thu, Apr 24, 2014 at 10:08 AM, Dominic Gross [dvgr...@gmail.com](mailto:dvgr...@gmail.com)wrote:
> > 
> > > So I can just write the two Documents (Apple and Mobilephone) to the  
> > > same Index (and the same Type?).

--  
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/CAHXA0\_1qyz4VsC8uLFwf9yAgkZs4cYYZFMxPzk7JPGm5hKEWwA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHXA0_1qyz4VsC8uLFwf9yAgkZs4cYYZFMxPzk7JPGm5hKEWwA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:33am UTC](https://discuss.elastic.co/t/best-way-to-store-variable-number-of-key-value-fields/17167/7 "2017-07-06T01:33:50Z")

</div>


