When you save an entity with Spring Data Elasticsearch the methods that do the save will return the saved entity. If the @Id
field was set to null before saving, the returned entity will have it set to the value that Elasticsearch created.
But as @Val pointed out: Don't do this, there's no need for this.
If you nevertheless want to create the id yourself, you might use the org.elasticsearch.common.UUIDs#base64UUID method, that's what Elasticsearch uses.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…