# Nested Document sorting and filtering

**URL:** <https://discuss.elastic.co/t/nested-document-sorting-and-filtering/17031>\
**Category:** Elasticsearch\
**Created:** [April 15, 2014, 7:06pm UTC](https://discuss.elastic.co/t/nested-document-sorting-and-filtering/17031 "2014-04-15T19:06:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivasan\_Ramaswamy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasan_ramaswamy/32/74106_2.png) [@Srinivasan\_Ramaswamy](https://discuss.elastic.co/u/Srinivasan_Ramaswamy)\
**Post date:** [April 15, 2014, 7:06pm UTC](https://discuss.elastic.co/t/nested-document-sorting-and-filtering/17031/1 "2014-04-15T19:06:30Z")

</div>

Hi

I have a document structure as follows

productId, productName, [ {tag1, tag\_name, price, tag\_category}, {tag2,  
tag\_name, price, tag\_category}, ...]

where tags is a nested document within a product. Each product is a unique  
item, but different merchants can sell the same product (called tags) so  
the price is different and hence the popularity is also different.

Here are my questions

1. I would like to filter the products by tag\_category. I read that nested  
filter can do this for me. In addition to returning all the products with a  
particular tag\_category, can it also return only the tags with the  
specified tag\_category within a product ?

2. Is there a way to sort the tags (nested documents) by tag price ? with  
or without the tag\_category constraints

3. In my index each product can have an average of 100 tags and i have 10m  
products and 1bn tags in total. Would you recommend nested document  
approach or parent-child approach. From what i have read till now I felt  
nested document is better.

Thanks  
Srini

--  
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/6e41c810-b41c-4180-8eb3-3b0a0cf7110a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6e41c810-b41c-4180-8eb3-3b0a0cf7110a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Srinivasan\_Ramaswamy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srinivasan_ramaswamy/32/74106_2.png) [@Srinivasan\_Ramaswamy](https://discuss.elastic.co/u/Srinivasan_Ramaswamy)\
**Post date:** [April 17, 2014, 5:43am UTC](https://discuss.elastic.co/t/nested-document-sorting-and-filtering/17031/2 "2014-04-17T05:43:12Z")

</div>

From what i read here

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

I understand that sorting is supported within a nested field.

In case of nested\_filter i would like to filter out the nested documents  
that doesnt match the query. I read in the forum that that feature is in  
development.

Please correct me if i am wrong.

Thanks  
Srini

On Tuesday, April 15, 2014 12:06:30 PM UTC-7, Srinivasan Ramaswamy wrote:

> Hi
> 
> I have a document structure as follows
> 
> productId, productName, [ {tag1, tag\_name, price, tag\_category}, {tag2,  
> tag\_name, price, tag\_category}, ...]
> 
> where tags is a nested document within a product. Each product is a unique  
> item, but different merchants can sell the same product (called tags) so  
> the price is different and hence the popularity is also different.
> 
> Here are my questions
> 
> 1. I would like to filter the products by tag\_category. I read that nested  
> filter can do this for me. In addition to returning all the products with a  
> particular tag\_category, can it also return only the tags with the  
> specified tag\_category within a product ?
> 
> 2. Is there a way to sort the tags (nested documents) by tag price ? with  
> or without the tag\_category constraints
> 
> 3. In my index each product can have an average of 100 tags and i have  
> 10m products and 1bn tags in total. Would you recommend nested document  
> approach or parent-child approach. From what i have read till now I felt  
> nested document is better.
> 
> Thanks  
> Srini

--  
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/0b00c736-3c4a-4ded-96f0-d85c485b13a7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0b00c736-3c4a-4ded-96f0-d85c485b13a7%40googlegroups.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:35am UTC](https://discuss.elastic.co/t/nested-document-sorting-and-filtering/17031/3 "2017-07-06T01:35:22Z")

</div>


