typesense-python icon indicating copy to clipboard operation
typesense-python copied to clipboard

Filtering json strings

Open EricOuma opened this issue 2 years ago • 0 comments

Description

I have two string fields that are part of my filter_by query: first_data and second_data. Either of these fields can have a value or none of them. Their values are set by encoding a Python dictionary to a json string e.g

first_dict = {'age':40}
second_dict = {}

first_data = json.dumps(first_dict, default=str)
second_data = json.dumps(first_dict, default=str)

Steps to reproduce

schema_fields = [
        {
            "name": "first_data", "type": "string",
        },
        {
            "name": "second_data", "type": "string"
        },
        {
            "name": "some_field", "type": "string[]"
        }
]

# Note that I am only checking for emptiness in both fields. There is probably a better approach for this by I wonder this doesn't work

{
  "q": "*",
  "filter_by": "first_data:!={} && second_data:!={} && some_field:=[A,B]"
}

Expected Behavior

I expect to only see results that either first_data or second_data have a value

Actual Behavior

I see results have both first_data and second_data equal to {} sample

Metadata

Typesense Version: 0.15.0

OS: Ubuntu 22.04.2 LTS

EricOuma avatar Apr 26 '23 16:04 EricOuma