redis-om-spring
redis-om-spring copied to clipboard
About query
Java Bean
@Data
@Document
public class Person {
@Id
private String
@TextIndexed
private String firstName;
@TextIndexed
private String lastName;
@TagIndexed
private String email;
@Indexed
private List<Phone> phoneList;
}
@Data
@Document
public class Phone {
@Id
private String phoneid;
@Searchable
private String phonename;
@Indexed
private BigDecimal price;
@Indexed
private String color;
@Indexed
private Integer test;
@Indexed(sortable = true)
private LocalDate date;
}
Question 1
Iterable<Person > findByPhoneList_color(String color);
or
@Query("@color:$color")
Iterable<Person > getColor(String color);
I can't get any results.
What should I do to get the result I want through color?
Question 2
Date is a localdate type.But when it is cached in redis, it is of long type.
When I query, the query log displays ‘yyyy-MM-dd’.
How can I get the corresponding date?
What should I do to filter data through date?
When I use
@Query("@date:$date")
Iterable<Phone> selectByDate(@Param("date")LocalDate now);
parameters: [2022-07-05]
queryOrParts: 0
query: @date:2022-07-05
When I code
Iterable<Phone> findByDate(Long date);
The error message : Could not create query for public abstract java.lang.Iterable
com.redis.om.documents.repositories.PhoneRepository.findByDate(java.lang.Long)!
Reason: Failed to instantiate [com.redis.om.spring.repository.query.RediSearchQuery]:
Constructor threw exception; nested exception is java.lang.IndexOutOfBoundsException:
Index 1 out of bounds for length 1;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.redis.om.spring.repository.query.RediSearchQuery]:
Constructor threw exception; nested exception is java.lang.IndexOutOfBoundsException:
Index 1 out of bounds for length 1
@BrightFutureSugar sorry just getting to this... any possibility you can send a reproducer project? But I would test again with the latest SNAPSHOT before doing so, the issue might be resolved. If it still fails, please open a new issue with the reproducer. Thanks!
Above, the only thing I see that's incorrect is that the child class is also annotated with @Document
, which implies it is its own collection, which does not work with Redis, the child class (in the List/Set) is meant to be an embedded part of the document.