In my spring project, I use annotations to define elasticsearch fields. As far as I understand, elasticsearch mappings are generated on startup of the app based on those annotations. However, mappings generated are different for different deployments.
I am running spring project with Java 8 and ElasticSearch 5.5.0.
Annotations:
@Size(min = MINIMUM_LENGTH_NAME, max = MAXIMUM_LENGTH_NAME)
@NotNull
@Column(name = "name", nullable = false)
@Field(store = Store.YES)
@Field(name = "name_forSort", normalizer = @Normalizer(definition = "lowercase"))
@SortableField(forField = "name_forSort")
private String name;
Expected mappings for name:
{
"mappings": {
"properties": {
"name" : {
"type" : "text",
"store" : true
},
"name_forSort" : {
"type" : "keyword",
"norms" : true,
"normalizer" : "lowercase"
}
}
}
}
Mappings for the problematic deployment:
{
"mappings": {
"properties": {
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name_forSort" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
}
}
}
The problem was solved by initiating a new ES instance followed by a reindex. It seems the weird mapping was caused by a previously failed reindex with corrupted data.