2016-02-19 8 views
5

का उपयोग करके लोचदार खोज के लिए _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 मान के बराबर हो।

कृपया मदद करें। धन्यवाद।

उत्तर

2

समस्या अपने गेटर में है यह @Id क्षेत्र के रूप में एक ही प्रकार के साथ public होना चाहिए:

public long getEvent_pk() { 
    return event_pk; 
} 
0

आप इसे मैप कर सकते हैं यदि आप फ़ील्ड नाम आईडी के साथ एक स्ट्रिंग प्रकार आईडी का उपयोग

private String id; 

यह काम किया। ऐसा लगता है कि केवल स्ट्रिंग प्रकार आईडी फ़ील्ड स्वीकार किया गया है।

संबंधित मुद्दे