I'm trying to write a lucene query to filter some data in RavenDB. Some of the documents in this specific collection are assigned a sequential number, and the valid ranges are not continuous (for example, one range can be from 100-200 and another from 1000 to 1400). I want to query RavenDB using Raven Studio (v2.5, the Silverlight client) to retrieve all documents that have values outside of these user-defined ranges.
This is the overly simplified document structure:
{
ExternalId: something/1,
SequentialNumber: 12345
}
To test, I added 3500 documents, all of which have a SequentialNumber
that's inside one of the following two ranges: 123-312
and 9000-18000
, except for one that has 100000123
. The ExternalId
field is a reference to the parent document, and for this test all the documents have the field set to something/1
. This is the Lucene query I came up with:
ExternalId: something/1 AND NOT
(SequentialNumber: [123 TO 321] OR SequentialNumber: [9000 TO 18000])
Running the query in RavenDB's Studio returns all the documents where SequentialNumber
isn't in the 123-321
range. I would expect it to only return the document that has 100000123
as a SequentialNumber
. I've been trying to Google for help, but so far I haven't found anything to steer me into the right direction.
What am I doing wrong?
RavenDB is indexing numbers in two ways, once as strings (which is what you see here) and once in numeric form. For range queries use:
The Ix prefix means that you are using int32