query OrderByQuery($query: String) {
orders(query: $query, first: 1) {
nodes {
id
email
name
}
}
}
{
"query": "metafields.my_app.my_field:the-value-i-am-serching"
}
As soon as you put metafields.non_existing_app.my_field or metafields.my_app.non_existing_fieldit will give you the first order.
It should still give you empty array! Same as it gives you now when you query with the existing metafield but the value is not present in any orders.
Are there any workarounds?
Hey @madfcat
From what I see here, this is expected behavior when a metafield definition doesn’t have filtering enabled. Do you have filtering enabled on this metafield definition?
More details on this in the troubleshooting guide.
Issue: Query returns all products/metaobjects instead of filtered results
Problem: Your query isn’t filtering results as expected, returning all items instead of just those matching your metafield criteria.
Solution: Ensure the metafield has filtering enabled.
Here are my draft order and order definition. I have matching draft order metafield definition for the order metafield definition.
As you can see, the filter is on.
Thanks for sharing that. To be sure I have this correctly, your query is searching within an existing metafield definition with filtering enabled, but the values you are searching within the existing definition don’t exist, and in that scenario, the search filter is being ignored?
Follow up:
I tested the above scenario on my development store to help clarify the behavior:
Test Setup:
- Created metafield definition
test_app.search_test with filtering enabled
- Added it to an order with the value “correct-value”
Test Results:
- Searching for the correct value → returned the order as expected

- Searching for a non-existent value within the existing definition → correctly returned 0 results

- Searching using a completely non-existent namespace → returned all orders (expected behavior since there’s no metafield definition for the system to filter against)
The third result is expected because without a definition, the query portion is effectively ignored. However, when using an existing filterable definition with a value that doesn’t exist in any order, it correctly returns an empty array.
Yes, that is what I am getting. I added additional check into my logic to see if the metafield exists before filtering against it.
Perfect! That sounds like a good solution. 