Since you are letting ES generate its own identifiers, i.e. you never call MyDao.setId("abcdxyz") , then _source cannot have a value in the id field.
What happens if you create your own identifiers and call setId("yourid") , then Spring Data ES will use it as the value for the _id your document, and also store this value in the _source.id field. This means that _source.id will not be empty.
If you do not call setId() , then _source.id will be null, and the ES will generate its own identifier. When you call getId() , Spring Data ES will definitely return the value of the _id field, not _source.id , since it is annotated with @Id
To answer your second question, it doesn't matter that the _source.id field is null ... until you need to reference it. Spring Data ES will always populate it when matching JSON documents with your Java entities, even if the base id field in ES is null.
Val
source share