# Query by range does not return all data

**URL:** <https://discuss.aerospike.com/t/query-by-range-does-not-return-all-data/421>\
**Category:** Query & Indexing\
**Tags:** secondary, garbage, index\
**Created:** [September 22, 2014, 9:03am UTC](https://discuss.aerospike.com/t/query-by-range-does-not-return-all-data/421 "2014-09-22T09:03:32Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![bbavn](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@bbavn](https://discuss.aerospike.com/u/bbavn)\
**Post date:** [March 26, 2015, 8:55am UTC](https://discuss.aerospike.com/t/query-by-range-does-not-return-all-data/421/7 "2015-03-26T08:55:32Z")

</div>

Hi Pratyyy,

regarding your questions:

1. No, only when using BETWEEN.

2. We have inserted the keys through aerospike\_put (by using the C client library)

3. The operations we typically do (apart from the initial bulk insert of the records using `aerospike_key_put`) are:

4. we run a query that selects on `as_integer_equals(0)` for the `in_use` field (w/ corresponding index). The callback for this query selects the string value in the `key` bin and returns it to the caller through the user data parameter and returns `false` to stop the query

5. after the foreach-query returns, we do an `aerospike_key_get` using the returned key to select that record.

6. next, we re-write that record with the `in_use` field set to (integer) 1 and with a `AS_POLICY_GEN_EQ` to ensure the record wasn’t modified in between

7. if the latter operation fails, we retry the whole procedure (up to a certain defined maximum)

Additionally, we have an operation to empty a set (having an API call for this would be highly appreciated, by the way!) that works by iterating over all the records in a set and, in its callback, will re-write that record with a TTL of 1 (we had a tombstoning bug with this previously) and subsequently calls `aerospike_key_remove`. We have been using this code for quite a while and have verified that it indeed removes the records. It might be that this operation has been called once (or more) on the mentioned set.

---

_[View the full topic](https://discuss.aerospike.com/t/query-by-range-does-not-return-all-data/421)._
