Skip to content

Define alias for document [DATAES-192] #767

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

Closed
spring-projects-issues opened this issue Aug 22, 2015 · 9 comments
Closed

Define alias for document [DATAES-192] #767

spring-projects-issues opened this issue Aug 22, 2015 · 9 comments

Comments

@spring-projects-issues
Copy link

Tim Schimandle opened DATAES-192 and commented

Currently spring data ES documents are defined by an index name that can be set via annotations on the document. This works well for simple cases in which a single index will suffice.

When a user wishes to do something more complex, like swap indexes dynamically, elasticsearch's reccomended way is to define an alias, and associate all operations to the alias. In the background the user can now build a second index with updated information and then direct elasticsearch to use that index by changing the reference in the alias.

Spring data ES does not currently support the definition of an alias on a document that will be used in all JPA default queries or by the elasticsearch template. This makes working with aliases difficult as it requires the user to abandon all of the default queries provided by the JPA implementation.

A solution to this problem would be to expose a property in the Document annotation that would define an aliasName. If present, an alias would be created and the underlying index would be associated with that alias. In all of the searching functions when an indexName is needed, if there is an aliasName the aliasName is used to perform the search. For functions that require access to the index directly the elasticsearch client can get a list of indexes associated with the alias and operate on them. The solution would have to handle the possibility of the alias already being created.

@Document(aliasName = "test-alias", indexName = "test", type = "test")


Affects: 1.2.2 (Fowler SR2)

Issue Links:

  • DATAES-864 Rework alias management
    ("is superseded by")

11 votes, 9 watchers

@spring-projects-issues
Copy link
Author

hung bang commented

Mohsin Husen Is there any pieces of information related to this issue?

 

@spring-projects-issues
Copy link
Author

wujun8 commented

This feature is certainly needed in the process of reindex

@spring-projects-issues
Copy link
Author

Erik Saly commented

Currently looking at reindexing, this would be really nice to have! Right now, it's a bit of a pain

@spring-projects-issues
Copy link
Author

Matt commented

Looking to being able to read from an index based on an alias, and this would be super helpful. 

@spring-projects-issues
Copy link
Author

Matt commented

Was able to get the document annotation reading from an alias by specifying indexName=aliasName, type=_doc, and createIndex=false. 
Using the latest version of spring data elasticsearch, this allowed us to read and write against the index with the aliasName

@spring-projects-issues
Copy link
Author

sothawo commented

Done with DATAES-864

@spring-projects-issues
Copy link
Author

hung bang commented

great job. Thanks sothawo , this will be very useful for us 

@eaudet
Copy link

eaudet commented Jan 13, 2021

What if I need thousands of aliases? Better yet, I have no idea how many aliases I need when creating the mapping.
If the number of aliases is unknown at the time you create the mapping, we need something else than you propose. For instance, if you need an alias for each users (to implement multi-tenancy). Then, I would like to see something like: @Document(aliasKey="user_id")
Then, you can PUT any document as the following (Spring data could create the alias query if it is not present.

PUT /user123/post/1 { "user_id": "user123", "title": "Easy recipe for ginger nuts", ... }

Would you recommend creating a new enhancement issue?

Found the solution here: #562

Will try it out!

@sothawo
Copy link
Collaborator

sothawo commented Jan 13, 2021

You do not create the aliases with the mapping. The mapping defines the fields within an index.
When you have a new user, you create a new alias, that's pretty simple to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants