7

के साथ काम नहीं कर रहा प्रतीत होता है मैं लोचदार खोज के लिए स्प्रिंग डेटा आरईएसटी का उपयोग करने की कोशिश कर रहा हूं। POST के लिए अंतर्निहित आरईएसटी नियंत्रक काम नहीं कर रहा प्रतीत होता है: जब मैं दस्तावेज़ पोस्ट करने का प्रयास करता हूं तो मुझे एक त्रुटि मिल रही है। मैं एक साधारण इकाई बनाई: इस मुद्दे को पुन: पेश करने के लिए आसान हैस्प्रिंग डेटा आरईएसटी elasticsearch

@Document(indexName = "user", type = "user", shards = 1, replicas = 0, refreshInterval = "-1") 
public class Customer { 

    @Id 
    private String id; 

    @Field(type = FieldType.String, store = true) 
    private String firstName; 

    @Field(type = FieldType.String, store = true) 
    private String lastName; 
    // getters and setters are skipped 
} 

भंडार:

public interface UserRepository extends ElasticsearchRepository<User, String> { 
} 

जब मैं सभी उपयोगकर्ताओं मैं प्रतिक्रिया हो रही है प्राप्त करने की कोशिश:

curl -X GET "http://localhost:9000/users" 
{ 
    "_links" : { 
    "self" : { 
    "href" : "http://localhost:9000/users{?page,size,sort}", 
    "templated" : true 
}, 
"search" : { 
    "href" : "http://localhost:9000/users/search" 
} 
}, 
"page" : { 
"size" : 20, 
"totalElements" : 0, 
"totalPages" : 0, 
"number" : 0 
} 
} 

लेकिन जब मैं उपयोगकर्ता को जोड़ने की कोशिश कर रहा हूं:

curl -i -X POST -H "Content-Type:application/json" http://localhost:9000/users -d '{"id":"4e9e62aa-7312-42ed-b8e4-24332d7973cd","firstName":"test","lastName":"test"}' 
कोई टिप्पणी बिना

{"cause":null,"message":"PersistentEntity must not be null!"} 

वहाँ एक Jira टिकट इस समस्या के लिए खोला गया प्रतीत हो रहा है:

मैं एक त्रुटि हो रही है Jira Issue

अगर यह संभव है के लिए CRUD बाकी नियंत्रक लेखन से बचने के लिए मैं सोच रहा हूँ वसंत डेटा Elasticsearch?

उत्तर

4

वैकल्पिक हल आवेदन वर्ग जहां RestElasticsearchRepositoryFactoryBean परिभाषित किया गया है

रूप
@SuppressWarnings("rawtypes") 
public class RestElasticsearchRepositoryFactoryBean 
    extends org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean { 
    @SuppressWarnings("unchecked") 
    @Override 
    public void afterPropertiesSet() { 
     setMappingContext(new org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext()); 
     super.afterPropertiesSet(); 
    } 
} 
+0

निर्माण करने के लिए

@EnableElasticsearchRepositories(repositoryFactoryBeanClass = RestElasticsearchRepositoryFactoryBean.class) 

टिप्पणी जोड़ने के लिए है! डंक – Tarion

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