Hi there,
I am using Redisearch 1.6.13 with redis 6 and the lettusearch Java client.
The index is simple and looks like the following:
public static Schema VISITOR_SCHEMA = Schema.builder()
.field(TagField.builder().name("projectId").build())
.field(NumericField.builder().name("lastSeen").sortable(true).build())
.build();
My purpose is to delete all documents that match a given projectId
field from the index.
While looking at solutions I read that conditional deletes could be supported in the future but it seems that’s not already the case. As an alternative, I was thinking to create a Lua script that performs a search by tag with the FT.SEARCH command, then to iterate over the results to execute a bulk delete.
I started to create a Lua script as follows:
local projectId = KEYS[1]
local visitors = redis.call("FT.SEARCH", "visitor", "@projectId:{" .. projectId .. "} NOCONTENT")
Then, I tested it in debug mode from the redis-cli command to see what value is returned:
FT.SEARCH visitor @projectId:{7eBIKQDUSvFrOqx2vOHY} NOCONTENT
[0]
An empty Array seems returned. If I remove the NOCONTENT
option, then I get the 3 documents I expect but with all fields. Is there a way to get only the document identifiers to iterate over for deletion? or is there a better approach?
Update:
Here is the script I currently use but it returns all fields before deleting:
local projectId = KEYS[1]
local visitors = redis.call("FT.SEARCH", "visitor", "@projectId:{" .. projectId .. "}")
local count = visitors[1]
for i = 2, (2 * count) + 1, 2 do
redis.call("FT.DEL", "visitor", visitors[i], "DD")
end