Nested facet filter (facet term output problem)


(Wesley Creteur) #1

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3b8321de-9703-4c72-9fcf-826b80ad20bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Binh Ly-2) #2

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ad6b378c-3eef-40cd-92a0-c955856964a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Wesley Creteur) #3

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/10bae3dc-dc32-4e93-9f23-002f18be88b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4