skip to Main Content

I am trying to delete a index using Jedis. I have the following…

    public void deleteAll() {
        // Optionally drop and recreate the index
        try (Connection connection = jedis.getPool().getResource()) {
            if (connection.isConnected()) {
                connection.sendCommand(SearchProtocol.SearchCommand.DROPINDEX, "DROPINDEX", "spring-ai-example", "DD"); // Use your configured index name
            } else {
                logger.warn("Connection is not valid");
            }
        } catch (Exception e) {
            // Index might not exist, that's okay
            logger.warn("Failed to drop index", e);
        }
    }

When I run it everything runs fine without error but the index doesn’t get removed…

redis-cli FT._LIST                     
1) spring-ai-example

What am I missing how do I delete an index?

The cli version does work…

redis-cli FT.DROPINDEX spring-ai-example DD

2

Answers


  1. Chosen as BEST ANSWER

    This worked

    connection.sendCommand(() -> SafeEncoder.encode("FT.DROPINDEX"), SafeEncoder.encode("spring-ai-example"), SafeEncoder.encode("DD"));
    

  2. You are sending DROPINDEX twice to the actual server command which should be just once.

    So just following should work:

    connection.sendCommand(SearchProtocol.SearchCommand.DROPINDEX, "spring-ai-example", "DD");
    

    On a side note: The sendCommand method in Connection object does not read the server reply but the executeCommand method does. So if you used executeCommand method, you would have got the command execution error in the server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search