# Help with creating mapping for my products

**URL:** <https://discuss.elastic.co/t/help-with-creating-mapping-for-my-products/19024>\
**Category:** Elasticsearch\
**Created:** [August 1, 2014, 9:14am UTC](https://discuss.elastic.co/t/help-with-creating-mapping-for-my-products/19024 "2014-08-01T09:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radu\_Gurita](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@Radu\_Gurita](https://discuss.elastic.co/u/Radu_Gurita)\
**Post date:** [August 1, 2014, 9:14am UTC](https://discuss.elastic.co/t/help-with-creating-mapping-for-my-products/19024/1 "2014-08-01T09:14:53Z")

</div>

I have this product JSON document that I generate from my database.

{  
"product": {  
"name": "My product",  
"description" : "My product description",  
"variations": [  
{  
"sku": "BLARED10",  
"price": 10.15,  
"attributes" : {  
"colour": "red",  
"size": 10,  
"material": "leather",  
"fastening": "lace"  
}  
},  
{  
"sku": "BLABLUE11",  
"price": 10.15,  
"attributes" : {  
"colour": "blue",  
"size": 11,  
"material": "leather",  
"fastening": "slip",  
"onSale": 1  
}  
}  
]  
}  
}

I am currently using this mapping for indexing it in elastic-search:  
{  
"product": {  
"properties": {  
"name": {"type": "string"},  
"description": {"type": "string"},  
"variations": {  
"type": "nested",  
"properties": {  
"sku": {"type": "string"},  
"price": {"type": "float"},  
"attributes" : {  
"type": "object"  
}  
}  
}  
}  
}  
}

Is this the correct way to map it, and if yes, how can I query for example  
all the products that have at least one variation with price 10.15 and  
colour blue?

Thanks!

--  
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/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [August 1, 2014, 5:07pm UTC](https://discuss.elastic.co/t/help-with-creating-mapping-for-my-products/19024/2 "2014-08-01T17:07:26Z")

</div>

With inner dccuments, you cannot query two different attributes for the  
same inner object. Internally, Elasticsearch/Lucene will flatten all the  
inner properties into one array. You would need to switch to nested  
documents or even parent/child documents in order to query on a single  
deeper document. Searching the mailing list/web will find lots of examples.  
Here are a couple:

> **[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.

> **[Fun with elasticsearch's children and nested documents - Space Vatican](https://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/)**
>
> When you’re indexing data, the world is rarely as simple as each document existing in isolation. Sometimes, you’re better off …

Cheers,

Ivan

On Fri, Aug 1, 2014 at 2:14 AM, Radu Gurita [gurita.radu@gmail.com](mailto:gurita.radu@gmail.com) wrote:

> I have this product JSON document that I generate from my database.
> 
> {  
> "product": {  
> "name": "My product",  
> "description" : "My product description",  
> "variations": [  
> {  
> "sku": "BLARED10",  
> "price": 10.15,  
> "attributes" : {  
> "colour": "red",  
> "size": 10,  
> "material": "leather",  
> "fastening": "lace"  
> }  
> },  
> {  
> "sku": "BLABLUE11",  
> "price": 10.15,  
> "attributes" : {  
> "colour": "blue",  
> "size": 11,  
> "material": "leather",  
> "fastening": "slip",  
> "onSale": 1  
> }  
> }  
> ]  
> }  
> }
> 
> I am currently using this mapping for indexing it in elastic-search:  
> {  
> "product": {  
> "properties": {  
> "name": {"type": "string"},  
> "description": {"type": "string"},  
> "variations": {  
> "type": "nested",  
> "properties": {  
> "sku": {"type": "string"},  
> "price": {"type": "float"},  
> "attributes" : {  
> "type": "object"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Is this the correct way to map it, and if yes, how can I query for example  
> all the products that have at least one variation with price 10.15 and  
> colour blue?
> 
> Thanks!
> 
> --  
> 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/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%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/CALY%3DcQAT0CBcnqi00qttGTNmqsunnaMr8wZJA7DL8LPe3diCeA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAT0CBcnqi00qttGTNmqsunnaMr8wZJA7DL8LPe3diCeA%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:11am UTC](https://discuss.elastic.co/t/help-with-creating-mapping-for-my-products/19024/3 "2017-07-06T01:11:35Z")

</div>


