Product query filter not working

I have the following specific request that isn’t working, and I need help to understand why.

Request ID: efa381b4-de8a-4a7d-8096-eeb67449be24-1762021823

The query filter is in the format: title:*'XX1'* OR title:*'XX2'* with about 10 total title values all following this exact format. For some reason the specific number or combination of filters used causes the query to return 0 results, even though they are all separated by OR, so it should match at least some. Removing the last filter field makes it work for some reason.

Hey,

I’d recommend checking out the search syntax for it as the syntax isn’t quite right here. Shopify API search syntax

You can only wildcard prefix of queries not on both sides Shopify API search syntax.

Quoting values will attempt to exact match them.

So I’d recommend for your query just doing something like title:XX1 OR title:XX2

1 Like

It doesn’t say anything about using multiple wildcards, it just says wildcards are supported. One thing is there might be multiple words in the title. What if the title itself contains a keyword or operator? That’s why I thought it best to quote them. It’s been working fine up until now. But I’ll play around with it some more. I wonder if there will be issues with other fields as well, or just title.

Hey David,

It mentions that it is prefix query

image

I’d recommend the query I mentioned as that won’t look for exact matches unless you quote the terms, it’ll be fuzzy by default.

I tried the new query, just like title:XX1 OR title:XX2 and it doesn’t work either. *’XXX’* behaves exactly the same in all cases it seems.

I’ve narrowed it down to the following that returns 0 products:

title:Bedding Set OR title:Advent Calendar

Without the OR, each one returns products on their own. It seems like a weird caching issue or something with the last term, since removing that from the whole query fixes it.

Is the query being provided as a GraphQL variable or are you hardcoding or interpolating it as a string in the query?

Hey @DavidT, the GraphQL Admin API includes a syntax debugger that shows exactly how your queries are being parsed. Every response includes an extensions.search object that breaks down the parsed query.

I tested your queries and here’s what the debugger revealed:

Your query: title:Bedding Set OR title:Advent Calendar

How it’s being parsed:

{
  "and": [
    {"field": "default", "match_all": "Calendar"},
    {"field": "title", "match_all": "Bedding"},
    {
      "or": [
        {"field": "default", "match_all": "Set"},
        {"field": "title", "match_all": "Advent"}
      ]
    }
  ]
}

Without quotes, multi-word terms get misparsed. Set and Calendar are being searched in the default field instead of title, creating conflicting AND conditions.

One way I found that worked good is to use default field search (searches all fields):

query: "Bedding OR Advent OR Calendar"
1 Like

Thanks, I couldn’t get it to work, but I see I just needed to set Shopify-Search-Query-Debug=1. I am testing the requests from Postman. It does seem the queries aren’t be parsed as I expected.

So is there no good way to do multi-word search queries? It seems there’s no way to ensure specific words come in the order they are listed if I have to search for each word individually.

I guess my only option is to use the default field instead, as you suggested, since that seems to support phrase queries.

When I was testing I could only get multi word queries with exact match:

query: "title:'Bedding Set' OR title:'Advent Calendar'"` 

Parsed as: {"or": [{"field": "title", "match_phrase": "Bedding Set"}, {"field": "title", "match_phrase": "Advent Calendar"}]}

and with prefix wildcards.

query: "title:Bed* OR title:Adv*"

Parsed as: {"or": [{"field": "title", "match_prefix": "Bed"}, {"field": "title", "match_prefix": "Adv"}]}