I defined the field in my entity using the @Id annotation. But this @Id does not map to _id in Elastic Search Documents. _Id values ββare automatically generated using Elastic Search.
I am using "org.springframework.data.annotation.Id;". Is this @Id supported by spring-data-es?
My essence:
import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; @Document( indexName = "my_event_db", type = "my_event_type" ) public class EventTransactionEntity { @Id private long event_pk; public EventTransactionEntity(long event_pk) { this.event_pk = event_pk; } private String getEventPk() { return event_pk; } }
My storage class:
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import com.softwareag.pg.pgmen.events.audit.myPackage.domain.EventTransactionEntity; public interface EventTransactionRepository extends ElasticsearchRepository<EventTransactionEntity, Long> { }
My application code:
public class Application { @Autowired EventTransactionRepository eventTransactionRepository; public void setEventTransactionRepository(EventTransactionRepository repo) { this.eventTransactionRepository = repo; } public void saveRecord(EventTransactionEntity entity) { eventTransactionRepository.save(entity); } public void testSave() { EventTransactionEntity entity = new EventTransactionEntity(12345); saveRecord(entity); } }
The ES request is executed (after saving):
http:
Expected Result:
{ "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "my_event_db", "_type": "my_event_type", "_id": "12345", "_score": 1, "_source": { "eventPk": 12345, } }] }}
The result obtained:
{ "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "my_event_db", "_type": "my_event_type", "_id": "AVL7WcnOXA6CTVbl_1Yl", "_score": 1, "_source": { "eventPk": 12345, } }] }}
You could see that the _id I got in my result was "_id": "AVL7WcnOXA6CTVbl_1Yl". But I would expect the _id field to be equivalent to the value of eventPk.
Please, help. Thanks.