I'm trying to set up the following mapping structure in Java High-Lever Rest API:
{
"mappings": {
"dynamic_templates": [{
"articleNumber": {
{
"match_mapping_type": "*"
},
{
"match": "articleNumber*"
},
{
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}]
}
}
I decided to use XContentBuilder for that:
XContentBuilder mapping = XContentFactory.jsonBuilder();
mapping.startObject()
.startObject("mappings")
.startArray("dynamic_templates")
.startObject("articleNumber")
.field("match_mapping_type", "*")
.field("match", "articleNumber*")
.startObject("mapping")
.field("type", "text")
.startObject("fields")
.startObject("keyword")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject()
.endArray()
.endObject();
return mapping;
Everything due to the instructions, but the following error was received:
com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
, and it points out to this line: .startObject("articleNumber")
.
Am I creating the JSON object wrong? Or the mapping structure is invalid?