# Java Filter Expression Range Filter not working

**URL:** <https://discuss.aerospike.com/t/java-filter-expression-range-filter-not-working/11099>\
**Category:** General Discussion\
**Created:** [May 13, 2024, 3:13pm UTC](https://discuss.aerospike.com/t/java-filter-expression-range-filter-not-working/11099 "2024-05-13T15:13:12Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [May 16, 2024, 4:56pm UTC](https://discuss.aerospike.com/t/java-filter-expression-range-filter-not-working/11099/9 "2024-05-16T16:56:01Z")

</div>

Please see the code example in [Fetch Secondary Index results from a Single Node using replication factor 128 - #7 by pgupta](https://discuss.aerospike.com/t/fetch-secondary-index-results-from-a-single-node-using-replication-factor-128/11094/7) That will work for AP or SC, regardless. For Queries, once you specify PREFER\_RACK, it will automatically use master or replica partitions on that rack to execute the query, whether it is AP mode or SC mode - no difference.

Specific code part:

```auto
//Instantiate client object with Preferred Rack ClientPolicy
//Here, this client is indicating, its preferred rack is with rack-id=1.
ClientPolicy cp = new ClientPolicy();
cp.rackId = 1; //Next, changed to 2 and then 3, for testing. 
cp.rackAware = true;
AerospikeClient client = new AerospikeClient(cp, "localhost", 3000);

//Run SI query
Statement stmt = new Statement();
stmt.setNamespace("test");
stmt.setSetName("testset");
stmt.setFilter(Filter.range("age", 20,30));
QueryPolicy qp = new QueryPolicy();

//Specify query to use preferred rack
qp.replica = Replica.PREFER_RACK;

RecordSet rs = client.query(qp, stmt);

while(rs.next()){
    Record r = rs.getRecord();
    Key thisKey = rs.getKey();  
    System.out.println(r);
}

//Close this client
client.close();

```

---

_[View the full topic](https://discuss.aerospike.com/t/java-filter-expression-range-filter-not-working/11099)._
