Reputation: 1
I want to create user index like below using spring-data-elasticsearch-2.1.0. annotation. I am not able to find any annotation to add "null_value": "NULL". This is required because our sorting order is failing.
"user": {
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"displayName": {
"type": "string",
"analyzer": "word_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"null_value": "NULL"
}
}
}
}
}
Domain class
private String firstName;
private String lastName;
@MultiField(
mainField = @Field(type = FieldType.String, analyzer = "word_analyzer"),
otherFields = {
@InnerField(suffix = "raw", type = FieldType.String, index = FieldIndex.not_analyzed)
}
)
private String displayName;
How to add "null_value": "NULL" through spring-data-elasticsearch annotation in InnerField? I do not want to creating index mapping externally.
Upvotes: 0
Views: 1038
Reputation: 31
Referring to https://jira.spring.io/browse/DATAES-312
This is an open issue(Fixed but not merged). This can be handled by adding "missing" : "_last"/"_first" and "unmapped_type" in sorting options..
These options("missing", "unmapped_type", "mode") are not available.
Putting "null_value": "NULL" will not have correct sorting order in string field.
"null_value": "0" can satisfy sorting order for integer field.
is it possible to do something in settings itself to achive one usecase usecase -- if sort direction is ASC then "missing" : "_first" and if sort direction is DESC then "missing" : "_last" .. which can be applied on raw field.
Upvotes: 0
Reputation: 309
At now it's only possible through @Mapping
annotation. Create JSON file with mapping definition:
{
"type": "string",
"index": "analyzed",
"analyzer": "word_analyzer",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed",
"null_value": "NULL"
}
}
}
And save it in your resources folder. In this example I save it in resources/elastic/document_display_name_mapping.json
.
Annotate field with @Mapping
annotation
@Mapping(mappingPath = "elastic/document_display_name_mapping.json")
private String displayName;
Upvotes: 1