Product Filters

We are calling product filter query using storefront API, we have followed the same method as mentioned in the document https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/products-collections/filter-products#query-products-by-price
But we are not getting all the products which are matching the filter there in our shopify store.

API details:
URL: https://staging-test-imadeya.myshopify.com/api/2023-01/graphql.json
Header: X-Shopify-Storefront-Access-Token
Method: POST
GraphQL:

query ProductFilter {
  collection(handle: "nihonshu") {
    handle
    products(
      first: 250,
      reverse: true,
    filters:[{productMetafield:{namespace:"customfilter",key:"type_of_alcohol",value:"γ«γ”γ‚Šι…’"}},{productMetafield:{namespace:"customfilter",key:"type_of_alcohol",value:"貴醸酒"}}]
    ) {
      edges {
        node {
        title
        }
      }
    }
  }
}

After the response products count should be: 91
[ステージング](http://Our%20shopify store with product filter)

But from the Storefront API we are getting only: 28

1 Like

Hi @AgRachithHegde

It looks like the issue might be related to the filter query you are using in your GraphQL request. The filters you are using seem to be searching for products with custom metafields that match either β€œγ«γ”γ‚Šι…’β€ or β€œθ²΄ι†Έι…’β€. However, the products in your collection might not have these exact metafield values.

1 Like

@okur90 Thank you for the reply

We have tried the same thing in our website with Shopify plugin to filter there i can see the proper product count.

1 Like

@AgRachithHegde

try running the following query to fetch a single product with one of the specified metafield values:

query {
  products(first: 1, query: "customfilter:type_of_alcohol:γ«γ”γ‚Šι…’") {
    edges {
      node {
        id
        title
      }
    }
  }
}

If you’re able to fetch a product using this query, it’s likely that the issue has to do with the query combining both filter conditions.

In that case, consider using a different approach: run two separate queries, one for each filter condition, and then merge the results.

query ProductFilterNigoriSake {
  collection(handle: "nihonshu") {
    handle
    products(first: 250, reverse: true, query: "customfilter:type_of_alcohol:γ«γ”γ‚Šι…’") {
      edges {
        node {
          title
        }
      }
    }
  }
}
query ProductFilterKijoshu {
  collection(handle: "nihonshu") {
    handle
    products(first: 250, reverse: true, query: "customfilter:type_of_alcohol:貴醸酒") {
      edges {
        node {
          title
        }
      }
    }
  }
}

Run these two queries separately, and then combine the results in your application code to get the full list of products that match either of the filter conditions.

If you’re still not getting the correct product count using these queries, double-check the access token and its permissions.

2 Likes

@okur90 I have tried individual filter same issue, when the products in a collection are more than 1000 this issue is there. For the filter we are not able to fetch proper product. So we have used reverse: true then also we are not able to get all the products.

1 Like