#13365·weaviate

Sorted search with a Like/range filter and a limit returns the wrong objects

Author: abankar1Created Oct 1, 2026Updated Oct 1, 2026
Labelscommunity

How to reproduce this bug?

A collection with a text property stringProp and 200 objects "element 0" … "element 199". Search with a filter that matches every object, a sort and a small limit:

  • filter id Like "*" (or stringProp GreaterThanEqual "0")
  • sort stringProp desc
  • limit: 3

The equivalent GraphQL is:

graphql
{ Get { C(where: {path: ["id"], operator: Like, valueText: "*"},
          sort: [{path: ["stringProp"], order: desc}], limit: 3) { stringProp } } }

I reproduced this at the DB layer on main (6aefed87b) with DB.ObjectSearch. A regression test comes with the linked PR.

What is the expected behavior?

Because the filter matches everything, the result should equal the unfiltered sorted result: element 99, element 98, element 97.

What is the actual behavior?

sort unfiltered (correct) with id Like "*"
desc, limit 3 99, 98, 97 2, 1, 0
asc, limit 3 0, 1, 10 0, 1, 2
desc, offset 3, limit 3 96, 95, 94 2, 1, 0 (same as page 1)

Root cause

inverted.Searcher.Objects resolves the filter with the search limit (s.docIDs(ctx, filter, className, limit)). For a multi-row read (Like, GreaterThan*, LessThan* on a filterable bucket), docBitmapInvertedRoaringSet/Set/Map stop once the allow list holds limit ids. That gives the first limit matches in index key order. s.sort(...) then sorts only that subset, so the query returns the top of whichever matches the reader met first, not the top of all matches. Offset makes it worse, because the index passes offset+limit as the shard limit and each page sorts a different prefix.

A single Equal row, deny lists (NotEqual/Not), And/Or with several children, and rangeable buckets all resolve without a cap, which is why most filters behave correctly.

Related (not fixed in the PR, needs a maintainer decision)

The same early stop also applies to unsorted filtered searches. There the page is the first offset+limit matches in key order, emitted in doc id order and then cut at offset. Paging through a Like-filtered result with offset can therefore skip some objects and return others twice, while a no-filter or deny-list listing pages consistently. Fixing this means giving up the early stop (a performance trade-off) or plumbing the offset to the shard, so the PR leaves it alone.

Server Version

main @ 6aefed87b