redis / redis-om-spring

Spring Data Redis extensions for better search, documents models, and more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modifying @Document attributes does not update the index attributes on redis

xMilos opened this issue · comments

I have an example class

@Data
@RequiredArgsConstructor(staticName = "of")
@AllArgsConstructor
@Document
public class StudentRedis {

    @Id
    private Long id;

    @NumericIndexed
    private Long studentId;

    @NumericIndexed
    private Long year;

} 

On app start this will create a json index in redis that will have 3 identifiers/attributes: for id , studentId and year.

But If I modify any of this or add new property example:

@Indexed
private String name;

**that attribute is not added to the redis index on next application restart, and I can't use that attribute for search. **

Is this intended or am i missing something?

Same happens if i remove @NumericIndexed annotation from field, that attribute stays in the redis index, even if it is deleted.

Only if i flushAll or drop the index in redis, the index gets recreated.
It seems that the code does not check if there was update to the @document compared to the redis index.

Is there a solution for this?

Hi! you can use "FT.DROPINDEX your_index" command in redis-cli terminal. when the application starts, the index will be created.

https://redis.io/commands/ft.dropindex/

Ok i just wanted to make sure that this is not supported by redis-om, will it be in future ?

commented

@xMilos you can use in code level,

@Autowired
RediSearchIndexer indexer;

@PostConstgruct
public void recreateIndex(){
indexer.dropAndRecreateIndexFor(xxxx.class);
}

Ok i just wanted to make sure that this is not supported by redis-om, will it be in future ?

I think this really needs to be implemented and I have an idea.

but still get an opinion @bsbodden