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.
1
Sep 13, 2023 (2 months ago)
Hasan
06:13 PMI 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:>price
[pseudoPrice]:>price
pseudoPrice:>[price]
It works in the following ways.
pseudoPrice:>105.5
price:>105.5
Doesn’t Typesense support direct field-to-field comparisons in queries?
Jason
06:51 PMHasan
06:52 PM1
Typesense
Indexed 3015 threads (79% resolved)
Similar Threads
Solving Bool Field Filtering Issue in Typesense
Guillermo was struggling with filtering by a bool field in Typesense. Jason assisted, and realized that Guillermo forgot to add the relevant field in the firebase-typesense extension configuration.
Troubleshooting Typesense API Sorting Error in Item Collections
Nikhil encountered a sorting error when using Typesense API due to an optional reference field in the items collection schema. Harpreet and Jason helped debug and identified a bug with sorting in general for 2 fields with the first one being the join field, promising a fix in a forthcoming build.
Solving Typesense Cloud Interface Issue in Python
Orion had an issue querying from Python in the Typesense Cloud interface. Kishore Nallan identified the problem within the array declaration. They then discussed improving error messages and Orion offered to make a PR.