-
Notifications
You must be signed in to change notification settings - Fork 1.3k
DATAES-233 Utility class to support rolling index strategy #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…annotations for a set of similar indices. The utility class should be registered as a bean (or spring boot auto config) to be used in index name expression language, which is a wrapper of thread local variable to avoid multi-thread issues.
…annotations for a set of similar indices. Add test cases for utility class.
…annotations for a set of similar indices. Update bugs in test cases and add comments in `Documents` annotation.
…annotations for a set of similar indices. Add ticket in test.
…annotations for a set of similar indices. Remove deprecated constructor.
Wouldnt using aliases accomplish the same thing? |
It seems not same.
|
The complex part will be how to decide what index to writer to and read from fo a given search.You end up trying to build a table-by-day like soluttion |
Page<Chat> s1 = repository.findBySender("s1", PageRequest.of(0, 10)); | ||
// then | ||
assertThat(s1.getTotalElements() == 2, is(true)); | ||
System.out.println(s1.getContent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
println here
Page<Chat> s1 = repository.findBySender("s1", PageRequest.of(0, 10)); | ||
// then | ||
assertThat(s1.getTotalElements() == 1, is(true)); | ||
System.out.println(s1.getContent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
println here
@Getter | ||
@NoArgsConstructor | ||
@Builder | ||
@Documents(indexPattern = "chat_#{indexNameVar.toString()}", type = "chat") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this reference a field in the document that contains date information?It feels like the reference should be to something in the object to be persisted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@field(name="createDate" store=false index= false)
private Date createDate
or @IndexVar
String getIndexName(){
return //date based logic based on pojo
}
@documents(indexPattern = "chat_#{getIndexName()}", type = "chat")
Can one of the contributers comment on the approach and the code. table by day is very popular and if there is no support many of my applications can not use spring-data-elastic |
@edwardcapriolo This PR is opened two years ago, I will try to recall the thought and consider your suggestions to adjust the implementation. |
I just wrote a comment in the jira issue, I would like to first challenge this solution, if it the best way to solve a problem like rolling indices. |
@sothawo I read your comment in jira. As far as I can see, the best practice is to put the index template in ES at the beginning, so we don't need to do any check for index existence and let ES do other thing. Then, we can just save entity to ES easily. As far as about the index name binding mechanism, @edwardcapriolo provides a suggestions: using a field in that entity, which is more intuitive. In that case, we can't use a global bean for root of Spring EL. We need to set the root object (Again, using thread local context to parse index name) before saving this kind of document, however, in that case, It seems only making index obj a little easier, and not for all other operation. Besides, it break the backward compatibility, so I wonder whether it is a better solution. @sothawo How do you think? |
why a ThreadLocal? What if some process submits tasks to a threadpool that insert into ES? Then these tasks run on different threads but should probably use the same index, although there are different name reolvers? Having the option to define a field on the object to provide the indexname - perhaps together with a But we need to have control over the creation of the index, because if we let Elasticsearch just create an index and store some document in it, then Elasticsearch will use the default mapping for the properties of the document, and we loose all the information that might be annotated with |
Maybe I not express clearly, but When it comes to index creation, index template is more convenient and suitable for this kind index partitioning as its official guide said. We can use |
The creation of a name for the index is business logic, that's right. The question is, how is the index name for the current document passed into Spring Data Elasticsearch? This can be for example by a bean resolved via SpEL. If this is not feasible, we could add an annotation like But there is the problem that for new indices, the But when the A different solution would be to support index templates like you mentioned, but this is not implemented yet. (2) I will create two tickets later for (1) and (2) Edit: |
DATAES-233 is closed as we now support index templates, and have an improved alias management. For how to get an index name dynamically from an entity I wrote a short example (https://www.sothawo.com/2020/08/use-an-index-name-defined-by-the-entity-to-store-data-in-spring-data-elasticsearch-4-0/). |
Uh oh!
There was an error while loading. Please reload this page.