Closed kapil-signity closed 3 years ago
@kapil-signity can you please share the index schema definition?
@gkorland
Client client = new Client("myIndexNew", "localhost", 6379);
Schema sc = new Schema()
.addTextField("title", 5.0)
.addTextField("body", 1.0)
.addNumericField("price");
// IndexDefinition requires RediSearch 2.0+
IndexDefinition def = new IndexDefinition()
.setPrefixes(new String[] {"item:", "product:"})
.setFilter("@price>100");
client.createIndex(sc, Client.IndexOptions.defaultOptions().setDefinition(def));
Map<String, Object> fields = new HashMap<>();
fields.put("title", "hello world");
fields.put("state", "NY");
fields.put("body", "lorem ipsum");
fields.put("price", 1337);
// RediSearch 2.0+ supports working with Redis Hash commands
try(Jedis conn = client.connection()){
conn.hset("item", fields);
}
Query q = new Query("hello world")
.addFilter(new Query.NumericFilter("price", 0, 1000))
.limit(0,5);
// actual search
SearchResult res = client.search(q);
System.out.println(res.totalResults); **<==== printing 0 as result**
I see two issues in your code example:
item:
while the hash key is item
--> this prefix can match keys like item:
, item:1
, items:2
....
I used the same code in Readme. SearchResult res = client.search(q); print(res.totalResults) <===Returning 0 always even item inserted in redis. see below snapshotshot