Implement product filter in Front End

Hey,

I'am looking to built a products filter. I found some other post with the same question :

And documentations explaining how to accomplish this :

The official docs and explanation seems great but my data is tructured different. In the official docs each filter category has its own field, like color, brand and model. The index that I'am using is more generic, like bellow:

"productFeatures" : [
        {
          "id" : 375495,
          "description" : "Brand",
          "aliasDescription" : "brand",
          "value" : "DELL",
          "aliasValue" : "dell"
        },
        {
          "id" : 362850,
          "description" : "Color",
          "aliasDescription" : "color",
          "value" : "Black",
          "aliasValue" : "black"
        },
        {
          "id" : 298755,
          "description" : "Model",
          "aliasDescription" : "model",
          "value" : "Laptop",
          "aliasValue" : "laptop"
        }]

In the example above, if I would filter on dell, I would most likely get the desired result, there is not a color named dell for example. But a lot of values are either Yes or No. For example, if there is a product feature 'ip6-rated' the value will be either Yes or No. Now, the returned values will probably not be the desired result, because the value Yes and No can also be used for other features. Thes wil be included in the results.

Currently I'am using the followinf query, wich is not working correctly

{
  "query": {
    "bool": {
      "filter": [
        {
          "query_string": {
            "query": "(productFeatures.aliasDescription.keyword:brand AND (productFeatures.aliasValue.keyword:dell)) AND (productFeatures.aliasDescription.keyword:color AND (productFeatures.aliasValue.keyword:red productFeatures.aliasValue.keyword:black))"
          }
         }
       ]
     }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.