redis / redis-om-spring

Spring Data Redis extensions for better search, documents models, and more
MIT License
609 stars 94 forks source link

Unable to filter on entityStream properly #486

Closed kmanchev-hedgeserv closed 4 months ago

kmanchev-hedgeserv commented 4 months ago

Hello, I encountered the issue of not able to filter on a field from my Object. The object looks like this: one abstract class that is extended by multiple objects that I am saving in Redis image

image

the EntityStream code that I try to filter with:

entityStream.of(ConcreteObjectDTO.class) .filter(ConcreteObjectDTO$.CLIENT_CODE.eq("0001QA")) .collect(Collectors.toSet()); In RedisInsight I see the fallowing query:

"FT.SEARCH" "com.path.to.my.dto.ConcreteObjectDTOIdx" "( @clientCode:0001QA)" "LIMIT" "0" "10000" "DIALECT" "1" This query returns 0 entries.

If I try filtering by id, it works as expected: entityStream.of(ConcreteObjectDTO.class) .filter(ConcreteObjectDTO$.ID.eq("0001QA:some:specific:id")) .collect(Collectors.toSet());

the query: "FT.SEARCH" "com.path.to.my.dto.ConcreteObjectDTOIdx" "( @id:{0001QA\\:some\\:specific\\:id})" "LIMIT" "0" "10000" "DIALECT" "1"

I tried to edit the original query in redis CLI by adding curly braces to the client code value like this :

"FT.SEARCH" "com.path.to.my.dto.ConcreteObjectDTOIdx" "( @clientCode:{0001QA})" "LIMIT" "0" "10000" "DIALECT" "1" and it works, but I am unable to figure out how to translate it to an entityStream code to behave the same... We use redis-om-spring version: 0.9.1 and java version: 21

bsbodden commented 4 months ago

Either use @Indexed or @Searchable but not both on the same field. Also @Id is by default indexed as TAG so no need to add the @Indexed on @Id. Use @Searchble only if you need full-text search capabilities, for field like clientCode you are probably searching by exact value, right?

To troubleshoot it, also provide the FT.INFO "com.path.to.my.dto.ConcreteObjectDTOIdx"

kmanchev-hedgeserv commented 4 months ago

It worked as expected. Thanks !