# Nested facet filter (facet term output problem)

**URL:** https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817
**Category:** Elasticsearch
**Created:** [April 4, 2014, 8:49am UTC](https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817 "2014-04-04T08:49:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Wesley\_Creteur](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@Wesley\_Creteur](https://discuss.elastic.co/u/Wesley_Creteur)
#### Post date: [April 4, 2014, 8:49am UTC](https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817/1 "2014-04-04T08:49:36Z")

</div>

Hi,

I'm programming my own faceted navigation for my webshop. I'm almost there  
but now i have a strange output on my facets. I will explain with an  
example.

This is my simplified query. This query give me the correct product hits,  
but my _Color_ facet gives 0 terms instead of 19. The _Manufacturer_ facet  
works just fine. When I remove the part in _bold_ the facet is working  
correctly. Is there anyone who know what the problem could be?

{  
"from": 0,  
"size": 60,  
"sort": {  
"oldPrice": "asc",  
"createdOnUtc": "desc"  
},  
"facets": {  
"Manufacturers": {  
"terms": {  
"field": "manufacturers.name",  
"size": 500  
}  
},  
"Color": {  
"global": true,  
"nested": "specificationAttributes.filterAttributeOptions",  
"terms": {  
"field": "specificationAttributes.filterAttributeOptions.name",  
"size": 500  
},  
"facet\_filter": {  
"bool": {  
"must": [  
{  
"term": {

"specificationAttributes.filterAttributeOptions.filterAttributeId": 1  
}  
}_,_

- 

```
       {*

```

- 

```
         "terms": {*

```

- 

```
           "manufacturerIds": [*

```

- 

```
             "33"*

```

- 

```
           ],*

```

- 

```
           "execution": "or"*

```

- 

```
         }*

```

- 

```
       }*
    ]
  }
}

```

}  
},  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"published": {  
"value": true  
}  
}  
},  
{  
"term": {  
"deleted": {  
"value": false  
}  
}  
},  
{  
"terms": {  
"categoryIds": [  
"2",  
"57",  
"23",  
"61",  
"25",  
"26",  
"27",  
"62",  
"28",  
"29",  
"30",  
"31",  
"54",  
"33",  
"32",  
"24"  
]  
}  
}  
]  
}  
},  
"filter": {  
"terms": {  
"manufacturerIds": [  
"33"  
],  
"execution": "or"  
}  
}  
}

--  
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/3b8321de-9703-4c72-9fcf-826b80ad20bc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3b8321de-9703-4c72-9fcf-826b80ad20bc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [April 4, 2014, 8:52pm UTC](https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817/2 "2014-04-04T20:52:06Z")

</div>

Don't know if this matters to you but if you do a nested in a facet, then  
the facet\_filter in it only applies to the nested object. Is it possible  
that you didn't intend that facet\_filter to execute on the nested object?

--  
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/ad6b378c-3eef-40cd-92a0-c955856964a0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ad6b378c-3eef-40cd-92a0-c955856964a0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Wesley\_Creteur](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@Wesley\_Creteur](https://discuss.elastic.co/u/Wesley_Creteur)
#### Post date: [April 8, 2014, 7:01am UTC](https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817/3 "2014-04-08T07:01:17Z")

</div>

Thx Binh Ly,

You made a good point. But when I do not nest the facet it does not perform  
the facet\_filter correctly. This is my mapping without nesting:

{  
"Product" : {  
"properties" : {  
"additionalShippingCharge" : {  
"type" : "double"  
},  
"adminComment" : {  
"type" : "string"  
},  
"allowBackInStockSubscriptions" : {  
"type" : "boolean"  
},  
"allowCustomerReviews" : {  
"type" : "boolean"  
},  
"allowedQuantities" : {  
"type" : "string"  
},  
"approvedRatingSum" : {  
"type" : "integer"  
},  
"approvedTotalReviews" : {  
"type" : "integer"  
},  
"automaticallyAddRequiredProducts" : {  
"type" : "boolean"  
},  
"availableEndDateTimeUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"availableForPreOrder" : {  
"type" : "boolean"  
},  
"availableStartDateTimeUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"backorderMode" : {  
"type" : "long"  
},  
"backorderModeId" : {  
"type" : "integer"  
},  
"callForPrice" : {  
"type" : "boolean"  
},  
"categories" : {  
"properties" : {  
"allowCustomersToSelectPageSize" : {  
"type" : "boolean"  
},  
"categoryTemplateId" : {  
"type" : "integer"  
},  
"createdOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"deleted" : {  
"type" : "boolean"  
},  
"description" : {  
"type" : "string"  
},  
"displayOrder" : {  
"type" : "integer"  
},  
"hasDiscountsApplied" : {  
"type" : "boolean"  
},  
"id" : {  
"type" : "integer"  
},  
"includeInTopMenu" : {  
"type" : "boolean"  
},  
"limitedToStores" : {  
"type" : "boolean"  
},  
"metaDescription" : {  
"type" : "string"  
},  
"metaKeywords" : {  
"type" : "string"  
},  
"metaTitle" : {  
"type" : "string"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"pageSize" : {  
"type" : "integer"  
},  
"pageSizeOptions" : {  
"type" : "string"  
},  
"parentCategoryId" : {  
"type" : "integer"  
},  
"pictureId" : {  
"type" : "integer"  
},  
"priceRanges" : {  
"type" : "string"  
},  
"published" : {  
"type" : "boolean"  
},  
"seName" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"showOnHomePage" : {  
"type" : "boolean"  
},  
"subjectToAcl" : {  
"type" : "boolean"  
},  
"updatedOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
}  
}  
},  
"categoryIds" : {  
"type" : "integer"  
},  
"createdOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"customerEntersPrice" : {  
"type" : "boolean"  
},  
"deleted" : {  
"type" : "boolean"  
},  
"deliveryDateId" : {  
"type" : "integer"  
},  
"disableBuyButton" : {  
"type" : "boolean"  
},  
"disableWishlistButton" : {  
"type" : "boolean"  
},  
"displayOrder" : {  
"type" : "integer"  
},  
"displayStockAvailability" : {  
"type" : "boolean"  
},  
"displayStockQuantity" : {  
"type" : "boolean"  
},  
"downloadActivationType" : {  
"type" : "long"  
},  
"downloadActivationTypeId" : {  
"type" : "integer"  
},  
"downloadExpirationDays" : {  
"type" : "integer"  
},  
"downloadId" : {  
"type" : "integer"  
},  
"fullDescription" : {  
"type" : "string"  
},  
"giftCardType" : {  
"type" : "long"  
},  
"giftCardTypeId" : {  
"type" : "integer"  
},  
"gtin" : {  
"type" : "string"  
},  
"hasDiscountsApplied" : {  
"type" : "boolean"  
},  
"hasSampleDownload" : {  
"type" : "boolean"  
},  
"hasTierPrices" : {  
"type" : "boolean"  
},  
"hasUserAgreement" : {  
"type" : "boolean"  
},  
"height" : {  
"type" : "double"  
},  
"id" : {  
"type" : "integer"  
},  
"imageUrl" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"isDownload" : {  
"type" : "boolean"  
},  
"isFreeShipping" : {  
"type" : "boolean"  
},  
"isGiftCard" : {  
"type" : "boolean"  
},  
"isRecurring" : {  
"type" : "boolean"  
},  
"isShipEnabled" : {  
"type" : "boolean"  
},  
"isTaxExempt" : {  
"type" : "boolean"  
},  
"length" : {  
"type" : "double"  
},  
"limitedToStores" : {  
"type" : "boolean"  
},  
"lowStockActivity" : {  
"type" : "long"  
},  
"lowStockActivityId" : {  
"type" : "integer"  
},  
"manageInventoryMethod" : {  
"type" : "long"  
},  
"manageInventoryMethodId" : {  
"type" : "integer"  
},  
"manufacturerIds" : {  
"type" : "integer"  
},  
"manufacturerPartNumber" : {  
"type" : "string"  
},  
"manufacturers" : {  
"properties" : {  
"allowCustomersToSelectPageSize" : {  
"type" : "boolean"  
},  
"createdOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"deleted" : {  
"type" : "boolean"  
},  
"description" : {  
"type" : "string"  
},  
"displayOrder" : {  
"type" : "integer"  
},  
"id" : {  
"type" : "integer"  
},  
"limitedToStores" : {  
"type" : "boolean"  
},  
"manufacturerTemplateId" : {  
"type" : "integer"  
},  
"metaDescription" : {  
"type" : "string"  
},  
"metaKeywords" : {  
"type" : "string"  
},  
"metaTitle" : {  
"type" : "string"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"pageSize" : {  
"type" : "integer"  
},  
"pageSizeOptions" : {  
"type" : "string"  
},  
"pictureId" : {  
"type" : "integer"  
},  
"priceRanges" : {  
"type" : "string"  
},  
"published" : {  
"type" : "boolean"  
},  
"seName" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"subjectToAcl" : {  
"type" : "boolean"  
},  
"updatedOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
}  
}  
},  
"maxNumberOfDownloads" : {  
"type" : "integer"  
},  
"maximumCustomerEnteredPrice" : {  
"type" : "double"  
},  
"metaDescription" : {  
"type" : "string"  
},  
"metaKeywords" : {  
"type" : "string"  
},  
"metaTitle" : {  
"type" : "string"  
},  
"minStockQuantity" : {  
"type" : "integer"  
},  
"minimumCustomerEnteredPrice" : {  
"type" : "double"  
},  
"name" : {  
"type" : "string"  
},  
"notApprovedRatingSum" : {  
"type" : "integer"  
},  
"notApprovedTotalReviews" : {  
"type" : "integer"  
},  
"notifyAdminForQuantityBelow" : {  
"type" : "integer"  
},  
"oldPrice" : {  
"type" : "double"  
},  
"orderMaximumQuantity" : {  
"type" : "integer"  
},  
"orderMinimumQuantity" : {  
"type" : "integer"  
},  
"parentGroupedProductId" : {  
"type" : "integer"  
},  
"preOrderAvailabilityStartDateTimeUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"price" : {  
"type" : "double"  
},  
"productAttributeOptionIds" : {  
"type" : "integer"  
},  
"productAttributes" : {  
"properties" : {  
"filterAttributeOptions" : {  
"properties" : {  
"count" : {  
"type" : "integer"  
},  
"filterAttributeId" : {  
"type" : "integer"  
},  
"id" : {  
"type" : "integer"  
},  
"isActive" : {  
"type" : "boolean"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
}  
}  
},  
"id" : {  
"type" : "integer"  
},  
"isVisible" : {  
"type" : "boolean"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
}  
}  
},  
"productCost" : {  
"type" : "double"  
},  
"productTemplateId" : {  
"type" : "integer"  
},  
"productType" : {  
"type" : "long"  
},  
"productTypeId" : {  
"type" : "integer"  
},  
"published" : {  
"type" : "boolean"  
},  
"recurringCycleLength" : {  
"type" : "integer"  
},  
"recurringCyclePeriod" : {  
"type" : "long"  
},  
"recurringCyclePeriodId" : {  
"type" : "integer"  
},  
"recurringTotalCycles" : {  
"type" : "integer"  
},  
"requireOtherProducts" : {  
"type" : "boolean"  
},  
"requiredProductIds" : {  
"type" : "string"  
},  
"sampleDownloadId" : {  
"type" : "integer"  
},  
"seName" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
},  
"shortDescription" : {  
"type" : "string"  
},  
"showOnHomePage" : {  
"type" : "boolean"  
},  
"sku" : {  
"type" : "string"  
},  
"specialPrice" : {  
"type" : "double"  
},  
"specialPriceEndDateTimeUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"specialPriceStartDateTimeUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"specificationAttributeOptionIds" : {  
"type" : "integer"  
},  
"specificationAttributes" : {  
"properties" : {  
"filterAttributeOptions" : {  
"properties" : {  
"count" : {  
"type" : "integer"  
},  
"filterAttributeId" : {  
"type" : "integer"  
},  
"id" : {  
"type" : "integer"  
},  
"isActive" : {  
"type" : "boolean"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
}  
}  
},  
"id" : {  
"type" : "integer"  
},  
"isVisible" : {  
"type" : "boolean"  
},  
"name" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"norms" : {  
"enabled" : false  
},  
"index\_options" : "docs"  
}  
}  
},  
"stockQuantity" : {  
"type" : "integer"  
},  
"subjectToAcl" : {  
"type" : "boolean"  
},  
"taxCategoryId" : {  
"type" : "integer"  
},  
"unlimitedDownloads" : {  
"type" : "boolean"  
},  
"updatedOnUtc" : {  
"type" : "date",  
"format" : "dateOptionalTime"  
},  
"userAgreementText" : {  
"type" : "string"  
},  
"vendorId" : {  
"type" : "integer"  
},  
"visibleIndividually" : {  
"type" : "boolean"  
},  
"warehouseId" : {  
"type" : "integer"  
},  
"weight" : {  
"type" : "double"  
},  
"width" : {  
"type" : "double"  
}  
}  
}  
}

But now my facet filter does not work. It gives all terms without filtering  
on the filterAttributeId:

{  
"from": 0,  
"size": 30,  
"sort": {  
"oldPrice": "asc",  
"createdOnUtc": "desc"  
},  
"facets": {  
"Manufacturers": {  
"terms": {  
"field": "manufacturers.name",  
"size": 500  
}  
},  
"Color": {  
"terms": {  
"field": "specificationAttributes.filterAttributeOptions.name",  
"size": 500  
},  
_"facet\_filter": {_

- 

```
   "terms": {*

```

- 

"specificationAttributes.filterAttributeOptions.filterAttributeId": [\*

- 

```
       "1"*

```

- 

```
     ]*

```

- 

```
   }*

```

- 

```
 }*

```

}  
},  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"published": {  
"value": true  
}  
}  
},  
{  
"term": {  
"deleted": {  
"value": false  
}  
}  
},  
{  
"terms": {  
"categoryIds": [  
"2",  
"57",  
"23",  
"61",  
"25",  
"26",  
"27",  
"62",  
"28",  
"29",  
"30",  
"31",  
"54",  
"33",  
"32",  
"24"  
]  
}  
}  
]  
}  
}  
}

Op vrijdag 4 april 2014 22:52:06 UTC+2 schreef Binh Ly:

> Don't know if this matters to you but if you do a nested in a facet, then  
> the facet\_filter in it only applies to the nested object. Is it possible  
> that you didn't intend that facet\_filter to execute on the nested object?

--  
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/10bae3dc-dc32-4e93-9f23-002f18be88b4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/10bae3dc-dc32-4e93-9f23-002f18be88b4%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:37am UTC](https://discuss.elastic.co/t/nested-facet-filter-facet-term-output-problem/16817/4 "2017-07-06T01:37:38Z")

</div>


