#community-help

Querying and Comparing Fields in Typesense

TLDR Hasan was having trouble comparing two fields in Typesense. Jason provided a response via GitHub. Hasan plans to create a boolean 'isDiscounted' in the database to solve the issue.

Powered by Struct AI

1

Sep 13, 2023 (2 months ago)
Hasan
Photo of md5-6280871b9236934e509469486e0cb925
Hasan
06:13 PM
Hello typesense team.
I want to compare 2 fields in the same document. I’m trying to get psuedoPrice values greater than price, but I don’t understand why it doesn’t work.
  const  fields= [
           {
                name: 'name',
                type: 'string',
            },
            {
                name: 'price',
                type: 'float',
                sort: true,
            },
            {
                name: 'pseudoPrice',
                type: 'float',
                sort: true,
            },
          
        ]

  const result = await client.collections<ProductSku>('productSku').documents().search({
                q: '*',
                query_by: '',
                filter_by: 'pseudoPrice:>price',
                per_page: 250,
            })

It gives the following error.
pseudoPrice not a float.
ways I’ve tried
pseudoPrice:&gt;price
[pseudoPrice]:&gt;price
pseudoPrice:&gt;[price]
It works in the following ways.
pseudoPrice:&gt;105.5
price:&gt;105.5
Doesn’t Typesense support direct field-to-field comparisons in queries?
Hasan
Photo of md5-6280871b9236934e509469486e0cb925
Hasan
06:52 PM
hank you, I will keep a boolean named isDiscounted in my database and solve it.

1