#community-help

Querying Typesense API with Array of Strings

TLDR Nikhilesh was struggling to query the typesense API with an array of strings. Kishore Nallan clarified the issue might be related to url encoding and further explained how to properly use the q and filter_by parameters.

Powered by Struct AI
+11
6
2mo
Solved
Join the chat
Jul 06, 2023 (2 months ago)
Nikhilesh
Photo of md5-de909ea1c98bd386c3722a0bddb03062
Nikhilesh
04:49 AM
Hey All,
I am facing a small issue while trying to query the typesense API with an array of strings

{{url}}/collections/{{collection_name}}/documents/search?q=[abc.com , abcd.com ]&query_by=server_name

The result contains only the records of the first server_name which is abc.com.
If I pass [abcd.com ,abc.com], the result contains the records of only abcd.com

Any ideas on what am I missing here?
Objective is to return the records from typesense collection for both abc.com and abcd.com
Thanks a lot :)
05:30
Nikhilesh
05:30 AM
Seems like the following is working for me.

{{url}}/collections/{{collection_name}}/documents/search?q=*&query_by=server_name&filter_by=server_name:[abcd.com , abc.com]

Please feel to suggest alternatives to the above use case.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:02 AM
👋 I wonder if this is a url encoding issue. Can you try the multi_search end-point? It sends the request as a POST body so no url encoding is done.
10:03
Kishore Nallan
10:03 AM
Also:

q=[ ,  ]

Is not a valid syntax. The q must be just a string. It's filter_by where you can provide list of strings.
10:03
Kishore Nallan
10:03 AM
So, actually your approach of using filter is correct.
+11
Jul 17, 2023 (2 months ago)
Nikhilesh
Photo of md5-de909ea1c98bd386c3722a0bddb03062
Nikhilesh
04:34 AM
Thank You! Kishore Nallan