#community-help

Issues with Using the OR Operator in Filter Query

TLDR Mehdi inquired about using OR in a filter query and was told by Kishore Nallan that only AND is supported. Ricardo suggested the use of multisearch and dedup, while Mehdi decided to modify the document's fields.

Powered by Struct AI

1

1

Jul 07, 2021 (31 months ago)
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:08 AM
Hello,

Is there a way to pass an or expression to the filter_by argument? Using "||" or "|" returns an Error 400 Could not parse the filter query
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:09 AM
The filter by query supports only basic operators. What query do you want to make?

1

Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:10 AM
For example filter by num_employees:>100 or country:= USA
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:11 AM
We currently support only && so you can do ANDing of conditions on two different fields, but can't do OR.
09:12
Kishore Nallan
09:12 AM
You can do OR within a single field by using a list filter operation, e.g: store_id: [100, 200, 300]
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
09:13 AM
multisearch and dedup on the client side, a bit more work involved but should do it.
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:37 AM
My solution is to add a field to my documents that contains the OR of the fields that i want to filter_by since they're all boolean
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:38 AM
👍 More flexible query operations is on roadmap, so hopefully you won't need it sometime in future 🙂

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Query on Typesense Support for Grouped Filter_by Functionality

Claudiu asked if typesense supports grouped filter_by. Kishore Nallan responded that it doesn't currently, but it's in their future plan. Jason suggested a temporary workaround.

3

9
31mo

Multiple Filters and JSON Requests in Typesense

Manish asked about multiple filter_by arguments, JSON input, and using multisearch. Jason offered typesense documentation links, examples, and how to use JSON formatted requests with multisearch. Ed shared a similar use case.

6

44
5mo

Performance Characteristics of Filtering Search Results

Oskar queries the performance difference in filtering search results. Jason clarifies how filters work and provides performance improvement suggestions like increasing vCPUs and sharding the collection. Kishore Nallan explains filter IDs and document ID matching. The thread concludes with discussions on performance tradeoffs in filter implementation.

33
15mo

Queries on String Sorting, Filter_by Operators and Typesense updates

Ishan asked about OR operators in TypeSense's filter_by fields and string sorting. Kishore Nallan clarified these functionalities. A workaround was proposed for cross-field ORs by Jason. This is on TypeSense's mid-term roadmap.

14
23mo

Typesense Cloud Filter Expression Issue

Samuel experienced a "Filter expression is not valid" error on a previously working query. Kishore Nallan assisted in troubleshooting and discovered it was a Scoped Search token formatting issue on Samuel's end.

2

32
6mo