See Sanity in action πŸ‘€ Join us for a live product demo + Q&A β†’

Issue with filtering documents using `match` query in Elasticsearch

1 replies
Last updated: Feb 19, 2023
Hi, I ran into an issue trying to filter documents with a
query. I'm trying to filter on a string field containing version number-like data - 1.2.3. So I though I could get all the "version 1.x"-related documents with
version match '1.*'
but it seems periods before the wildcard -
- for some reason does not work.
version match '1.2.3'
returns documents, but
version match '1.*'
does not.. πŸ˜• I don't see the documentation mentioning
being a special character in this context. Is this a bug?
Feb 19, 2023, 3:35β€―PM
operator is made for human text, and can't be used this way. A string like
is turned into the tokens
[1, 2, 3]
, and then matched against the text, which is also tokenized this way. So
"1.2.3" match "3.2.1"
returns true.
If you only want to search by prefix, I recommend using
, e.g.:
string::startsWith(version, "1.")
This will match
, etc.
Feb 19, 2023, 6:55β€―PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in