# Problem nested filter

**URL:** <https://discuss.elastic.co/t/problem-nested-filter/22186>\
**Category:** Elasticsearch\
**Created:** [February 16, 2015, 12:43pm UTC](https://discuss.elastic.co/t/problem-nested-filter/22186 "2015-02-16T12:43:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_jaeger](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Stefan\_jaeger](https://discuss.elastic.co/u/Stefan_jaeger)\
**Post date:** [February 16, 2015, 12:43pm UTC](https://discuss.elastic.co/t/problem-nested-filter/22186/1 "2015-02-16T12:43:33Z")

</div>

Hi,  
sorry for my bad english.

i have a little product search project.

in this project i have one program (main product) with similiars product  
types (product) i.e. program in size XXL.  
in this product-type i have nested price objects with country and currency.  
now i want to facet the price by range by given country token. but my price  
range filter loop over all prices, not the given country price.

where´s my error in brain?

have anybody an idea?

here´s my mapping

"mappings": {  
"program": {  
"\_all": {  
"enabled": true,  
"index\_analyzer": "nGram\_analyzer",  
"search\_analyzer": "whitespace\_analyzer"  
},  
"\_source": {  
"enabled": true,  
"compress": true  
},  
"dynamic": "strict",  
"properties": {  
"title": {  
"type": "string",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"programmid": {  
"type": "string",  
"store": true,  
"index": "analyzed",

"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"shippingcountry": {  
"include\_in\_all": false  
"type": "string",  
"store": true,  
"index": "analyzed",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"products": {  
"type": "nested",  
"store": true,  
"index": "analyzed",  
"fields": {  
"raw": {  
"type": "nested",  
"index": "not\_analyzed"  
}  
},  
"properties": {  
"size": {  
"include\_in\_all": false  
"type": "string",  
"store": true,  
"index": "analyzed",  
"analyzer": "english",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"prices": {  
"type": "nested",  
"store": true,  
"index": "analyzed",  
"analyzer": "english",  
"fields": {  
"raw": {  
"type": "nested",  
"index": "not\_analyzed"  
}  
},  
"properties": {  
"price": {  
"type": "float",  
"store": true,  
"index": "analyzed",  
"null\_value": 0,  
"analyzer": "english",  
"fields": {  
"raw": {  
"type": "float",  
"index": "not\_analyzed"  
}  
}  
},  
"country": {  
"include\_in\_all": false  
"type": "string",  
"store": true,  
"index": "analyzed",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
},  
"currency": {  
"include\_in\_all": false  
"type": "string",  
"store": true,  
"index": "analyzed",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

and my request

{  
"sort": [  
{  
"title.raw": {  
"order": "asc"  
}  
}  
],  
"size": 0,  
"from": 0,  
"aggs": {  
"productprices": {  
"nested": {  
"path": "products"  
},  
"aggs": {  
"prices": {  
"nested": {  
"path": "products.prices"  
},  
"aggs": {  
"min\_price": {  
"query": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": {

"products.prices.country.raw": "GB"  
}  
}  
]  
}  
}  
},  
"range": {  
"field": "products.prices.price",  
"ranges": [  
{  
"to": 50  
},  
{  
"from": 50,  
"to": 100  
},  
{  
"from": 100  
}  
]  
}  
}  
}  
}  
}  
}  
},  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"shippingcountry.raw": "GB"  
}  
},  
{  
"nested": {  
"path": "products",  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"nested": {  
"path":  
"products.prices",  
"query": {  
"filtered":  
{

"query": {

"match\_all": {}  
},

"filter": {

"bool": {

"must": [

```
{
                                                                        
    "term": {
                                                                        
        "products.prices.country.raw": "GB"
                                                                        
    }
                                                                        
}

```

]  
}  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}  
}

--  
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/83c37580-adf7-4e38-9515-1bc4e0d79daf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/83c37580-adf7-4e38-9515-1bc4e0d79daf%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, 12:32am UTC](https://discuss.elastic.co/t/problem-nested-filter/22186/2 "2017-07-06T00:32:29Z")

</div>

Closed on July 6, 2017, 12:32am UTC


