How to Create a Range Query Against Range Data

In some data models such as for apartment rentals, there is not an exact price for an item but rather a minimum price and a maximum price. Both the minimum price and maximum price are indexed in distinct dimensions. The query is also constructed using a range.

For example, you want to find apartments whose rental range is between $500 and $600.

The desired outcome can be expressed using this diagram:

--                   A low miss
                  -- B high miss
    -----            C within range, extending below
            ----     D within range, extending above
   -------------     E within range, extends beyond 
       ----          F within range
    500     600

The following query will consider C through F to exact matches and A and B to be fuzzy.

Effectively you are then performing this query:

!(rent_min > 600 || rent_max < 500)

Which can be rewritten as:

rent_min <= 600 && rent_max >= 500

This can be represented, using scalar interval notation, as a Discovery query like this, where cullDistance is the range beyond which the price of those apartments are considered completely out of range:

  "criteria": [
      "dimension": "rent_min", 
      "value": "(,600]",
      "cullDistance": 100
      "dimension": "rent_max", 
      "value": "[500,)", 
      "cullDistance": 100