is there a way to supply multiple filter_by argume...
# community-help
m
is there a way to supply multiple filter_by arguments? I'm looking at https://typesense.org/docs/0.24.1/api/search.html#filter-parameters , but there isn't any example of that.
Also, if all of the filter_bys are done via url params, then how do you run "&&", etc., mentioned elsewhere?
j
You can use any complex expressions in filter_by. Eg:
Copy code
filter_by: field1:=a && field2:=b
You want urlencode the value of the filter_by parametr
m
I see. let me try that. It would be good to have an example of this in the docs.
j
It’s documented under this table: https://typesense.org/docs/0.24.1/api/search.html#filter-parameters Under “Multiple Conditions”
m
I saw that. But, I think having an example with the full query params, is what I was looking for.
j
Ok will update this snippet right on top to include more parameters as examples: https://typesense.org/docs/0.24.1/api/search.html#search
👍 1
There’s also a way to automatically have curl urlencode the parameters
m
is there a way to pass these arguments as JSON? My list of arguments is getting long and cumbersome
j
Yeah the multi-search endpoint supports JSON: https://typesense.org/docs/0.24.1/api/federated-multi-search.html
You can send a single search into it, even though it’s called multi-search
m
and it would take these as well? exclude_fields, highlight_fields, per_page, etc.?
j
Yup, any search parameters
m
cool, let me try that. Should simplify.
Ahh... So much better with JSON! No weird URL encoding stuff.
😄 1
e
I have an interesting use case and looking at multisearch [although just working on the idea now] I have a search query [free text], example Operations Manager Filters: employment-type = ‘full-time’, job-type=‘remote’, country = ‘Germany’ these are all facets with counts on them. Naturally when you pick a filter - example full time, the count for all other employment-types is set to 0. I need to be able to show the count for part-time aswell even though you clicked on ‘full-time’, also other filters now would reflect the total count, example, job-type now has only 10 full-time jobs that are of job-type = remote. The idea is to send another query to get facet counts using existing query + filters, except for the ones you’re active on, example on the employment-type. This query would look like this: search: Operations Manager, Filters: job-type = ‘remote’, country = ‘Germany’ You see I purposely didn’t include the ‘employment-type’ filter, this way it would me facet counts for full-time and part time.
am I headed on the right direction here?
j
Yup, that’s the exact approach you want to take
Here’s an example of this in action: https://ecommerce-store.typesense.org/ If you open the browser dev console, and then the network tab, then click on some of the filters, you’ll see the type of queries generated inside the multi-search request
e
but to improve the response time these can be done in one http request?
j
Correct, that’s the multi_search endpoint
e
awesome
what size cluster does this run on?
j
That example runs on a cluster that has a few other indices as well - 32GB RAM, 4vCPUs, SDN (in Oregon, Frankfurt, Mumbai)
message has been deleted
Probably has around 34M records across all collections
The products collection itself is tiny - probably 50MB
e
got it 😄
thanks for sharing
👍 1
https://showcase-nextjs-typesense-ecommerce-store.vercel.app/ just this could run on 2vCPU and 1GB memory?
j
Yup, even 0.5GB RAM should be sufficient
e
awesome
thanks again
👍 1
m
This stumped me -- the
query_by
parameter is outside the JSON, while all the rest of them are within the JSON. Why?
j
That’s just an example of how you can set parameters common to all searches as query parameters. And you can override individual search parameters inside the JSON
You can just leave out query_by in the query parameter if you don’t need this mechanism
m
So, query_by can be inside the JSON as well?
j
Correct
m
Hmm... maybe I missed it. Would be good to have a full example of all the possible parameters / keys possible in a JSON request to TS.
j
You can use any of the search parameters listed here, inside a multi_search request: https://typesense.org/docs/0.24.1/api/search.html#search-parameters
👍 1
Essentially, you want to think of a multi_search request as a batch of individual search requests
m
Yeah, there's reference. And there are full examples. I think it would be good to expand the documentation with lots of examples.
👍 1