Hi guys! I have a couple of questions about filter...
# community-help
a
Hi guys! I have a couple of questions about filtering: 1. I have an optional field called
fabric_type
. How can I filter my search to return only documents that have
fabric_type=null
? 2. I have a
string[]
field called
certifications
. How can I filter my search to return only documents that do not have empty array as a value (so documents that have some values)? Thanks!
f
Hey there! So Typesense doesn't include a way to filter by an optional field existing or not existing. What I would suggest you try out, is create another mandatory field for each optional field called
<field>_exists
(
fabric_type_exists
) and set that to true or false, depending on the document itself. For array types, you could even count the number of
certifications
for example and have that as an
int32
field, so filter by
certifications_count:>0
(useful for boosting documents with more certifications by sorting by that field)
If you're just looking at sorting, we have a built-in way to do this: https://typesense.org/docs/27.1/api/search.html#sorting-null-empty-or-missing-values This won't completely omit missing values from the results, but sort them based on them existing or not
We're also tracking what you're describing as a feature request on GitHub: https://github.com/typesense/typesense/issues/790 So stay tuned on that!
a
Thank you very much!
🙌 1