का उपयोग करके लोचदार खोज के लिए _id फ़ील्ड को कैसे सेट करें मैंने @Id एनोटेशन का उपयोग करके अपनी इकाई में एक फ़ील्ड परिभाषित किया है। लेकिन यह @Id लोचदार खोज दस्तावेज़ों में _id पर मैपिंग नहीं कर रहा है। _id मान स्वचालित रूप से लोचदार खोज द्वारा उत्पन्न होते हैं।स्प्रिंग डेटा
मैं "org.springframework.data.annotation.Id;" का उपयोग कर रहा हूं। क्या यह @Id वसंत-डेटा-एस द्वारा समर्थित है?
मेरे इकाई:
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;
}
}
मेरे भंडार वर्ग:
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import com.softwareag.pg.pgmen.events.audit.myPackage.domain.EventTransactionEntity;
public interface EventTransactionRepository extends ElasticsearchRepository<EventTransactionEntity, Long> {
}
मेरे आवेदन कोड:
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);
}
}
ES क्वेरी निष्पादित (सहेजें के बाद):
http://localhost:9200/my_event_db/my_event_type/_search
अपेक्षित परिणाम:
{
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_event_db",
"_type": "my_event_type",
"_id": "12345",
"_score": 1,
"_source": {
"eventPk": 12345,
}
}]
}}
प्राप्त परिणाम:
{
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_event_db",
"_type": "my_event_type",
"_id": "AVL7WcnOXA6CTVbl_1Yl",
"_score": 1,
"_source": {
"eventPk": 12345,
}
}]
}}
आप _ id मैं अपने परिणाम में मिला देख सकता था था, "_ id": "AVL7WcnOXA6CTVbl_1Yl"। लेकिन मैं उम्मीद करता हूं कि _id फ़ील्ड EventPk मान के बराबर हो।
कृपया मदद करें। धन्यवाद।