I am trying to use Spring Data REST to search for elastics. The built-in REST controller for POST does not seem to work: I get an error when trying to publish a document. The problem is easy to reproduce: I created a simple object:
@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;
Repository:
public interface UserRepository extends ElasticsearchRepository<User, String> { }
When I try to get all users, I get the answer:
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 } }
but when I try to add a user:
curl -i -X POST -H "Content-Type:application/json" http://localhost:9000/users -d '{"id":"4e9e62aa-7312-42ed-b8e4-24332d7973cd","firstName":"test","lastName":"test"}'
I get an error message:
{"cause":null,"message":"PersistentEntity must not be null!"}
The Jira ticket seems to be open for this problem without comment: Jira Issue
I am wondering if it is possible to write CRUD REST controllers for Spring Data Elasticsearch?
spring-data spring-data-rest spring-data-elasticsearch elasticsearch
MrkK
source share