While creating an index Elasticsearch Repository does not allow default type. If field type annotation is missing, assuming default type, the Spring data elasticsearch mapper throws exception and then creates some default mapping when I save the first object. I'm wondering if it is somehow possible to not annotate every field in of my data objects? I'm using Spring Data Elasticsearch v3.1.8 and Elasticsearch 6.2.2. Thanks
0
votes
1 Answers
0
votes
There is effectively a way to avoid annoting every fields. Elasticsearch need to create the mapping of the document.
You can indicate to spring how the document need to be mapped with @Field
or by providing the mapping configuration.
With spring just annotate the document with @Mapping
to set mapping file location.
Also you could just create the mapping using Elasticsearch PUT mapping API.
@Document(indexName = Produit.INDEX, type = ProduitES.TYPE, shards = 1)
@Mapping(mappingPath = "/mappings/mappings-produit.json")
public class Produit {
private String code;
private String name;
...
}
The mapping file in resources/mappings/mappings-produit.json
folder :
{
"produit": {
"dynamic": "strict",
"properties": {
"code": {
"type": "text",
},
"name": {
"type": "text",
"index": false
}
}
}
}
@Document
annotated entity and the exception you get from the Mapper? – P.J.Meisch