redis / redis-om-spring

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

[Bug] Search query is not getting generated for `@Indexed` annotation #492

Closed Suvink closed 2 months ago

Suvink commented 3 months ago

Observed behaviour

I have the following Document model:

public class OAuth2Authorization implements Serializable {

    @Indexed
    @NonNull
    @Id
    private String id;

    @Indexed
    private String authorizationCodeValue;

    ... other properties
}

When I start my server up, I observe the following index being created from the Redis Insights profiler:

14:26:51.101 [0 172.17.0.1:43772] "FT.CREATE" "com.my.path.OAuth2AuthorizationIdx" "ON" "JSON" "PREFIX" "1" "OAuth2Authorization" "LANGUAGE" "english" "SCHEMA" "$.id" "AS" "id" "TAG" "SEPARATOR" "|"

Note that this does not include the authorizationCodeValue field.

Then I've defined a repository method to fetch an object by the authorizationCodeValue:

public interface OAuth2AuthorizationRepository extends RedisDocumentRepository<OAuth2Authorization, String> {
    List<OAuth2Authorization> findByAuthorizationCodeValue(String authorizationCodeValue);
}

When I execute this method, it returns empty and I observe the following query being executed in the profiler:

14:28:48.658 [0 172.17.0.1:49360] "FT.SEARCH" "com.my.path.OAuth2AuthorizationIdx" "" "LIMIT" "0" "10000"

Note that the actual search query is empty.

However, when I add @Searchable annotation to the model in addition to the @Indexed annotation, I see the index correctly being configured and the query being constructed properly. I did not use @Searchable because I don't have a requirement for full-text capabilities and just want to match the entire value.

14:30:02.071 [0 172.17.0.1:45392] "FT.CREATE" "com.my.path.OAuth2AuthorizationIdx" "ON" "JSON" "PREFIX" "1" "OAuth2Authorization" "LANGUAGE" "english" "SCHEMA" "$.authorizationCodeValue" "AS" "authorizationCodeValue" "TEXT" "$.id" "AS" "id" "TAG" "SEPARATOR" "|"
14:32:33.361 [0 172.17.0.1:60450] "FT.SEARCH" "com.my.path.OAuth2AuthorizationIdx" "@authorizationCodeValue:FETPuFaWQpumP5yip_pyOpblxDDdeht7ihiDdBGbLEeuksxzao_Fi2JNFWPAZ5USmguO5JVq11jiTJzLWhsAa18yL3Zury_GIxi9JPHDQEyHU\\-67A0V5XFOWtnfK1UNi" "LIMIT" "0" "10000"

Expected behaviour

When a field is annotated with @Indexed annotation, the correct index and the search query should be created.

Additional Info:

bsbodden commented 3 months ago

It should work, don't see anything weird in the code that would prevent the field from getting indexed. The field in the entity must have a getter/setter as per JavaBean conventions. And you can drop the @Indexed from the id field, but other than that it looks fine.

bsbodden commented 2 months ago

@Suvink did you resolve this?