Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Prefix when creating an Index using Jredisearch #2249 #166

Closed
gkorland opened this issue Sep 19, 2021 · 4 comments
Closed

Adding Prefix when creating an Index using Jredisearch #2249 #166

gkorland opened this issue Sep 19, 2021 · 4 comments

Comments

@gkorland
Copy link
Contributor

ref RediSearch/RediSearch#2249 (@chaitradalawai)

I am not sure if this is the right place to ask help regarding Jredisearch, please do guide me if I need to ask in different platform.

I use Jredisearch(com.redislabs:jredisearch:2.0.0) for querying using Redisearch. I want to add a prefix while creating the Index. I am able to add prefix using the below Redisearch command,
FT.CREATE MyIndex ON HASH PREFIX 1 doc: SCHEMA name TEXT

But not able to find options for the same when writing in Java. I use the following code in Java,
client.createIndex(schema, Client.IndexOptions.defaultOptions());

Could you help me on how do we add Prefix when using Jredisearch?

@gkorland
Copy link
Contributor Author

gkorland commented Sep 19, 2021

// 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));

You can see the full example in the README https://github.com/RediSearch/JRediSearch/blob/master/README.md

@chaitradalawai
Copy link

Hi,
Thanks for the help. I am able to set prefix in JRedisearch.

@chaitradalawai
Copy link

I need info on dropping Indexes in Redisearch using JRedisearch, please help.

I want to delete the existing content of my Indexes and add new data daily. I couldn't find anything for this as client.deleteDocument() methods need docids. So, I am dropping the index using client.dropIndex(true) and recreating it. I am getting the below exception when adding the documents after recreating the index
Code:
client.dropIndex(true);
Schema schema = new Schema()
.addTextField("param1", 5.0)
.addTextField("param2", 5.0)
.addTextField("param3", 5.0);
IndexDefinition indexDefinition = new IndexDefinition().setPrefixes("myprefix:");
client.createIndex(schema, Client.IndexOptions.defaultOptions().setDefinition(indexDefinition));
client.addDocument("myprefix:"+docId, 1, fields);

Exception
{"@timestamp":"2021-09-22T01:20:03.782+02:00","message":"Unexpected error occurred in scheduled task","level":"ERROR","thread":"scheduling-1","logClass":"o.s.s.s.TaskUtils$LoggingErrorHandler","logMethod":"handleError","stack_trace":"r.c.j.e.JedisDataException: Document already exists\n\tat redis.clients.jedis.Protocol.processError(Protocol.java:132)\n\tat redis.clients.jedis.Protocol.process(Protocol.java:166)\n\tat redis.clients.jedis.Protocol.read(Protocol.java:220)\n\tat redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:278)\n\tat redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196)\n\tat io.redisearch.client.Client.addDocument(Client.java:491)\n\tat io.redisearch.client.Client.doAddDocument(Client.java:467)\n\tat io.redisearch.client.Client.addDocument(Client.java:454)\n\tat io.redisearch.client.Client.addDocument(Client.java:637)\n\tat

I am guessing documents aren't deleted when dropping the index, I saw a command FT.DROPINDEX DD where DD is for deleting documents.
Could you Please tell me the corresponding option for setting 'DD' in jredisearch?

@sazzad16
Copy link
Collaborator

sazzad16 commented Sep 23, 2021

@chaitradalawai There is not direct support at this moment.

PS: Please put different question in different/new issues.

Note: Created #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants