RediSearch / JRediSearch

Java Client for RediSearch
https://redisearch.io
BSD 2-Clause "Simplified" License
141 stars 62 forks source link

Java client API supporting Redisearch #187

Closed chaitradalawai closed 2 years ago

chaitradalawai commented 2 years ago

I have been using Redisearch through JRedisearch API in my project. I recently got to know this API is deprecated. It would be really helpful if you could provide the alternative API and links for examples if published any.

sazzad16 commented 2 years ago

JRediSearch is deprecated in favor of Jedis. There's a quick start guide. More example can be found in search tests and aggregation tests.

PS: @chaitradalawai Where have you found the information for deprecation? Asking because same doc should also contain the reference to Jedis.

chaitradalawai commented 2 years ago

I got to know in this forum itself #185, when asking about some other question.

Thanks for links. It would be really helpful to know the below things:

  1. Please tell when will the JRediSearch be removed completely, as I had used this in my cache projects and have to move to new approach.
  2. What is the dependency to be included in the project for jedis support?
  3. Is the new API support a long term one OR it will be changed again ?
  4. Does the below code connect to multiple hosts ? Set nodes = new HashSet<>(); nodes.add(new HostAndPort("127.0.0.1", 7379)); nodes.add(new HostAndPort("127.0.0.1", 7380)); JedisCluster client = new JedisCluster(nodes);
sazzad16 commented 2 years ago
  1. If you notice, the full sentence says "Please notice JRediSearch is deprecated and you should use Jedis 4.2 which has built in support for RediSearch."
  2. Never. But its development is stopped. So there won't be any update (until and unless the decision is reverted).
  3. You can check dependencies of Jedis 4.2.3 here.
  4. I can't promise anything. It's development. But such major change is unlikely to happen in near future.
  5. That's cluster mode. You're not supposed to use it if don't know what it is.
chaitradalawai commented 2 years ago

Thanks for the clarification.

chaitradalawai commented 2 years ago

Hi, I was using the below code to create client object with host port and index names, I think the Client object has to be replaced with JedisPooled in Jedis approach, could you please tell which syntax to use to pass password arg ?

io.redisearch.client.Client.Client(String indexName, String host, int port, int timeout, int poolSize, String password)

chaitradalawai commented 2 years ago

And also please tell about the corresponding jedis methods for the below JRedisearch code

  1. is there any similar method for the Client object creation to access Redis( above question) ----- io.redisearch.client.Client.Client(String indexName, String host, int port, int timeout, int poolSize, String password) ?

  2. I am dropping the index and recreating it on scheduled basis using the method (client.dropIndex(true) - missingOk If the index does not exist, don't throw an exception instead return false), where it doesn't throw exception even if the index doesn't exist, if I use the "redis.clients.jedis.UnifiedJedis.ftDropIndexDD(String indexName)" it gives the following exception when loading data for the first time (redis.clients.jedis.exceptions.JedisDataException: Unknown Index name )----------- I am doing this operation since there is no functionality to remove all the docs from the index. Is there any method which deletes all the records from an index or check if an index is existing already for supporting removing and reloading all the data on scheduled basis?

  3. I am using the following code to load all the documents by replacing the old ones with new io.redisearch.client.Client.addDocument(String docId, double score, Map<String, Object> fields, boolean noSave, boolean replace, byte[] payload) ----------- is there any similar method in Jedis to replace existing docs with new ones ?

sazzad16 commented 2 years ago

@chaitradalawai

  1. Not directly. You may provide GenericObjectPoolConfig<Connection> for the poolSize.
GenericObjectPoolConfig<Connection> config = new ConnectionPoolConfig();
config.setMaxTotal(poolSize);

UnifiedJedis client = new JedisPooled(config, host, port, timeout, password);
  1. No.

You may consider following:

public static boolean safeFtDropIndexDD(UnifiedJedis jedis, String indexName) throws JedisException {
  try {
    return "OK".equals(jedis.ftDropIndexDD(indexName));
  } catch (JedisDataException jde) {
    if (jde.getMessage().toLowerCase().contains("unknown")) {
      return false;
    }
    throw jde;
  }
}
  1. Document has been removed/deprecated from RediSearch. You can either use HASH or JSON data structure.
chaitradalawai commented 2 years ago

Hi,

About 3rd question, I am using the following code to load all the documents by replacing the old ones with new io.redisearch.client.Client.addDocument(String docId, double score, Map<String, Object> fields, boolean noSave, boolean replace, byte[] payload) ----------- is there any similar method in Jedis to replace existing docs with new ones ?

  1. I see the document in jedis implementation "redis.clients.jedis.search.Document", is this deprecated too ?
  2. I want to refresh my cache data by replacing old value with new ones, which was supported through above mentioned method in JRedisearch, is there a similar approach in Jedis ? I see "hset" is there in Jedis for adding a new document, does this also replace if given the same key ? (i.e. key = Index_prefix:unique_id )
sazzad16 commented 2 years ago
  1. "redis.clients.jedis.search.Document" is not deprecated (yet).
  2. Yes; existing fields will be replaced and new fields will be added.
chaitradalawai commented 2 years ago

Will the "redis.clients.jedis.search.Document" be deprecated as well? I see in the SearchResult class the only result returning data structure is Document, will this be changed later or am I missing something here ?

List getDocuments()-------- https://github.com/redis/jedis/blob/master/src/main/java/redis/clients/jedis/search/SearchResult.java

sazzad16 commented 2 years ago

At this moment, there is no such plan.

chaitradalawai commented 2 years ago

thanks for all the answers :)