Weaviate schema for filter operation

Hi team,

I am working on Weaviate hybrid search with filters and I want to match numeric values in queries with ingested data.

Example 1

  • Data: "The price of the apple is 80."

  • Query: "Show me items with price less than 90."

  • Filter: Filter.by_property("price").less_than(90)

  • :white_check_mark: I correctly get this record in the response.

Example 2

  • Data: "The price of the banana is between 50 and 80."

  • :red_question_mark: Now, I’m unsure how to store this information in the price field.

    • If I store it as an array [50, 80], it won’t work with comparison operators like < or >.

    • But if I store just one number, I lose the range meaning.

Question: How should I ingest data in such cases where the property represents a range (e.g., 50–80), so that I can still apply filters effectively?

hi @Rohini_vaidya !!

You can filter with multi conditions. For example:

from weaviate.classes.query import Filter
response = collection.query.fetch_objects(
    # Use & as AND
    #     | as OR
    filters=(
        Filter.by_property("price").greater_or_equal(50) &
        Filter.by_property("price").less_or_equal(80)
    ),
    limit=3
)

Is this what you are looking for?

THanks!

Hi @DudaNogueira ,
filters=( Filter.by_property(“price”).greater_or_equal(50) & Filter.by_property(“price”).less_or_equal(80) )
We can do it at query time.

However, I am now extracting the numbers from my data and ingesting them into a numerical field.
Now, for the record, “The price of the banana is between 50 and 80.”
The numbers extracted will be an array. In this case, how can I ingest it into a number field?
To apply the comparison filter, the data type must be int, not number_array.

so, my question is while ingesting data into weaviate how to store array of numbers ?

Hey @Rohini_vaidya

The trick here is to treat a range as two numbers instead of one. If you try to stuff [50, 80] into a single field, Weaviate won’t know how to run < or > on it. But if you split it into price_min and price_max, you can keep using all the normal comparison operators without any weird workarounds.

Example schema

{
  "properties": [
    { "name": "price_min", "dataType": ["number"] },
    { "name": "price_max", "dataType": ["number"] }
  ]
}

How you’d store data

  • “The apple is 80.” => price_min = 80, price_max = 80

  • “Banana is between 50 and 80.” => price_min = 50, price_max = 80

(If there’s only one number, just set both fields the same.)

How you’d query

# less than 90
Filter.by_property("price_max").less_than(90)

# between 50 and 80
Filter.by_property("price_min").greater_or_equal(50) &
Filter.by_property("price_max").less_or_equal(80)

This way:

  • You get clean numeric filters that just work.

  • No headaches with arrays.

  • Works for all kinds of ranges prices, dates, weights, etc.

Super simple pattern, but it keeps your hybrid search + filtering fast and predictable :rocket: