'How to mark a reference as unindexed in Spring data cloud datastore
We have @Unindexed annotation to mark a field as unindexed. But it doesn't work with a reference type field. Source:- https://cloud.spring.io/spring-cloud-static/Greenwich.RC1/multi/multi__spring_data_cloud_datastore.html
@Entity(name = "kind_one")
class Test {
@Unindexed
private String someFieldOne; //works - property is unindexed
@Unindexed
private List<TestTwo> someFieldTwo; //doesn't work - property is still indexed
}
@Entity(name = "kind_two")
class TestTwo{
@Unindexed
private String someFieldThree;
}
When storing the Test object in datastore, "someFieldOne" is marked as unindexed, but "someFieldTwo" is marked as indexed.
Any lead will be appreciated.
Thanks!
Solution 1:[1]
For Lists the entire list must not be excluded from being indexed instead its values must be individually excluded from being indexed as mentioned in the comments here. Otherwise it will throw an exception.
I believe this is the reason why someFieldTwo is getting indexed in your case as it is a List barring the fact that it should throw an exception as per the comment.
So I would suggest you exclude the list elements individually as mentioned in this example instead of annotating the whole list with @unindexed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Prabir |
