I want to store unspecified json payload data in an Elasticsearch index using Spring Data with the following entity
@Document(indexName = "message")
public class Message {
@Id
private String id;
private JsonNode payload;
//getters and setters here
}
The payload varies and needs to be stored in a generic way that can also be easily loaded again that's why I'd like to use the JsonNode here.
A document with "id" gets written but the field "payload" is empty.
When I look up the document written to the index in Kibana it looks like this:
_class:
com.tryout.Message
payload:
id:
30243006-0844-4438-a7f0-db93518b340f
_id:
30243006-0844-4438-a7f0-db93518b340f
_type:
_doc
_index:
message
_score:
0
In the index mapping "payload" also wasn't created and it looks like this:
{
"mappings": {
"_doc": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
Any ideas how I can get my generic payload stored?
(I'm using Elastic v7.9.2 & Spring Booot + spring-boot-data-jpa v2.3.5 and spring-data-elasticsearch v4.1.1)
JsonNode(from Jackson?). This class has no properties, so there's nothing in a JsonNode that Spring Data Elasticsearch can write. You'll need a customConverterthat is able to convert from a JsonNode to aMap<String, Object>and back .