Skip to content

[Thank Goodness It’s Search]: Building Faceted Navigation for Retail Catalogs - Part 4 leveraging post_filter for improved search experience

5 minute read
Content level: Intermediate
1

This article demonstrates how to use post_filter to enhance search functionality by enabling users to freely navigate product catalog taxonomies in any direction, without being constrained by their search parameters.

Welcome to Thank Goodness It's Search series—your Friday fix of OpenSearch learnings, feature drops, and real-world solutions. I will keep it short, sharp, and search-focused—so you can end your week with more search knowledge than you started with.

This article extends our previous 3-part series on implementing faceted navigation for e-commerce product catalogs, where we covered nested field types and navigation patterns. While those articles focused on the faceting structure, they didn't address showing filtered search results. Let's say you want to find a 'Magenta' lipstick that's both Vegan and suitable for Dry and Oily skin. Normally when you select 'Dry', the results get filtered to only show Dry products, hiding other filters such as 'Oily' under the same facet. This is because the search results control the generated aggregations.

Here's another scenario, with say a product catalog for footwear. You need a red shoe, so you searched for "red shoe" and chose category footwear, brand Asics and size 9. Say you didn't find a red shoe of size 9, but you can now see on the left navigation , an option to choose a different brand or a different color and you quickly choose Nike to see if such a shoe exists. Sounds familiar? I'm sure you've done this countless times! This the power of post_fitler.

post_filters are powerful because they allow us to apply filters after aggregations are built. Here, the filtered search results don't limit which facet options are shown. This means, you can traverse the product catalog top-down or bottom-up without restricting the facets to display only those filters that apply to the current resultset. The product catalog taxonomy becomes agnostic of the search results, allowing users with even casual browsing to see the possibilities of the catalog offering ! This also means you can now enable multi-select, selecting multiple filters from within the same facet such as Oily and Dry skin types at the same time or in the case of the footwear catalog, show brands that are both Nike and Asics!.

To build the post_filter, you will be using the same index and dataset that you built in the Building top-down Faceted Navigation for Retail Catalogs: Part 2 - Nested queries in OpenSearch article.

Using post_filter to show all color variant, grouped by subcategory

In this example we are grouping the filters within the color facet by subcategory.

GET /cosmetic-makeup-index/_search
{
  "size": 1000,
  "_source": {
    "includes": ["category","subcategory","axiology", "skintype"]
  },
  "query": {
    "match_all": {}
  },
  "aggs": {
    "variants": {
      "nested": {
        "path": "skuinfo"
      },
      "aggs": {
        
        "color": {
          "terms": {
            "field": "skuinfo.color.keyword",
            "size": 20
          },
          "aggs": {
            "back_to_cat": {
              "reverse_nested": {},
              "aggs": {
                "by_cat": {
                  "terms": {
                    "field": "subcategory.keyword",
                    "size": 20
                  }
                }
              }
            }
          }
        }
      }
    }
  }, 
  "post_filter": {
    "bool": {
      "filter":[
        {"term": {"category.keyword":"Makeup"}},
        {"term": {"subcategory.keyword":"Lipstick"}}
      ]
    }
  }
}

In the above example, you would see that even though the filters are applied to results for category Makeup and subcategory Lipstick, all the color filters are displayed. Now lets get to building the actual feature we discussed above!

Enabling multi-select on your aggregations

In the below example, you will be able to see all the fiters for category, subcategory, skintype, axiology and the nested skuinfo color but restrict the results to just show the 2 results for category=Makeup, subcategory=Lipstick and skintype=Oily.

GET /cosmetic-makeup-index/_search
{
  "size": 1000,
  "_source": {
    "includes": ["category","subcategory","axiology", "skintype"]
  },
  "query": {
    "match_all": {}
  },
  "aggs": {
    "cat": {
      "terms": {
        "field": "category.keyword",
        "size": 100
      }
    },
    "subcat": {
      "terms": {
        "field": "subcategory.keyword",
        "size": 100
      }
    },
    "skintype": {
      "terms": {
        "field": "skintype.keyword",
        "size": 100
      }
    },
    "axiology": {
      "terms": {
        "field": "axiology.keyword",
        "size": 100
      }
    },
    "variants": {
      "nested": {
        "path": "skuinfo"
      },
      "aggs": {
        "color": {
          "terms": {
            "field": "skuinfo.color.keyword",
            "size": 100
          } 
        }
      }
    }
  }, 
  "post_filter": {
    "bool": {
      
      "filter":[
        {"term": {"category.keyword":"Makeup"}},
        {"term": {"subcategory.keyword":"Lipstick"}},
        {"term": {"skintype.keyword":"Oily"}}
      ]
    }
  }
}

By showing all available filters regardless of current selection, users can explore the full product catalog without being restricted by their previous filter choices. This improves product discoverability and creates opportunities for cross-selling while delivering an enhanced shopping experience.

Conclusion

OpenSearch post_filter enable flexible faceted navigation by separating filter application from aggregation building. This allows you to:

  • Show all available facet options regardless of current filter selections
  • Enable multi-select filtering within the same facet
  • Make product catalog taxonomy navigation independent of search results
  • Support both top-down and bottom-up catalog exploration
  • Improve product discovery and cross-selling opportunities
  • Create a more intuitive and flexible shopping experience

The combination of nested fields for variant data and post_filter for faceted navigation provides a robust foundation for building modern e-commerce search experiences.

Call for action

Try implementing post_filter in your product catalog search to enable multi-select faceting. Start with a simple use case like enabling multi-select on color filters, then expand to other facets like size, brand etc. Share your experience in the comments below - what challenges did you face? How did it improve your users' search experience? Did you try it with the k-NN (vector) search?? Check out the final part in this series, aggregation best practices!

Want to learn more ? Check out the reference links below to learn more about OpenSearch aggregations techniques.

References

See you next Friday with another search solution in the Thank Goodness It's Search series! Until then, happy searching! 🔍