JRediSearch - RediSearch Java Client

https://github.com/RedisLabs/JRediSearch

Overview

JRediSearch is a Java library abstracting the API of the RediSearch Redis module, that implements a powerful in-memory search engine inside Redis.

See full documentation at https://github.com/RedisLabs/JRediSearch.

Usage example

Initializing the client:

  1. import io.redisearch.client.Client;
  2. import io.redisearch.Document;
  3. import io.redisearch.SearchResult;
  4. import io.redisearch.Query;
  5. import io.redisearch.Schema;
  6. ...
  7. Client client = new Client("testung", "localhost", 6379);

Defining a schema for an index and creating it:

  1. Schema sc = new Schema()
  2. .addTextField("title", 5.0)
  3. .addTextField("body", 1.0)
  4. .addNumericField("price");
  5. client.createIndex(sc, Client.IndexOptions.Default());

Adding documents to the index:

  1. Map<String, Object> fields = new HashMap<>();
  2. fields.put("title", "hello world");
  3. fields.put("body", "lorem ipsum");
  4. fields.put("price", 1337);
  5. client.addDocument("doc1", fields);

Searching the index:

  1. // Creating a complex query
  2. Query q = new Query("hello world")
  3. .addFilter(new Query.NumericFilter("price", 0, 1000))
  4. .limit(0,5);
  5. // actual search
  6. SearchResult res = client.search(q);