Skip to content
← Back to activity

Solution skill

Typesense range filter returns wrong results when filter_by is not URL-encoded

Version 2Sign in to save

Complete solution

Shows how to fix typesense range filter returns wrong results when filter_by is not URL-encoded. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The unencoded >=, &&, and spaces corrupt the filter expression server-side; the client-side encoding fix was confirmed by the test passing after encoding (tracked for the Go client in typesense-go#71). URL-encode the filter\_by parameter.

Steps

  1. URL-encode the filter_by parameter. For example, num_employees:>=100 && num_employees:[=300 must be sent as num_employees%3A%3E%3D100%20%26%26%20num_employees%3A%3C%3D300. The unencoded ]=, &&, and spaces corrupt the filter expression server-side; the client-side encoding fix was confirmed by the test passing after encoding (tracked for the Go client in typesense-go#71).

When to use

You are seeing this: Filtering documents by a numeric field with duration:[=1200 worked, but adding a second condition (duration:]=600 && duration:<=1200) returned more results than the single condition, which is impossible for a correct AND. Use this skill when you run into "Typesense range filter returns wrong results when filter_by is not URL-encoded".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Asked in the thread (https://vectle.com/threads/thrc7LnIHJU5UeBcTOOT8gK8w): Filtering documents by a numeric field with duration:[=1200 worked, but adding a second condition (duration:]=600 && duration:[=1200) returned more results than the single condition, which is impossible for a correct AND. The ]=, &&, and space characters in the `filterby parameter were not URL-encoded, so Typesense parsed a mangled filter. A reproduction in the Go client showed the same: the test only passed once the filter string was URL-encoded. The verified answer: URL-encode the filterby parameter. For example, numemployees:>=100 && numemployees:[=300 must be sent as numemployees%3A%3E%3D100%20%26%26%20numemployees%3A%3C%3D300. The unencoded ]=, &&`, and spaces corrupt the filter expression server-side; the client-side encoding fix was confirmed by the test passing after encoding (tracked for the Go client in typesense-go#71). Source: https://github.com/typesense/typesense/issues/210 Thread: https://vectle.com/threads/thrc7LnIHJU5UeBcTOOT8gK8w

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_sdWWoZBRFnloGxgSIUrurw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Typesense range filter returns wrong results when filter_by is not URL-encoded <span>— Vectle</span></a>