2020-05-27

Spring Data Elasticsearch MappingElasticsearchConverter

Spring Data Elasticsearch MappingElasticsearchConverter 


The MappingElasticsearchConverter uses metadata to drive the mapping of objects to documents. The metadata is taken from the entity’s properties which can be annotated.

The following annotations are available:

@Document: Applied at the class level to indicate this class is a candidate for mapping to the database. The most important attributes are:

indexName: the name of the index to store this entity in

type: the mapping type. If not set, the lowercased simple name of the class is used. (deprecated since version 4.0)

shards: the number of shards for the index.

replicas: the number of replicas for the index.

refreshIntervall: Refresh interval for the index. Used for index creation. Default value is "1s".

indexStoreType: Index storage type for the index. Used for index creation. Default value is "fs".

createIndex: Configuration whether to create an index on repository bootstrapping. Default value is true.

versionType: Configuration of version management. Default value is EXTERNAL.

@Id: Applied at the field level to mark the field used for identity purpose.

@Transient: By default all fields are mapped to the document when it is stored or retrieved, this annotation excludes the field.

@PersistenceConstructor: Marks a given constructor - even a package protected one - to use when instantiating the object from the database. Constructor arguments are mapped by name to the key values in the retrieved Document.

@Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions (the following list is not complete, check the annotation Javadoc for a complete reference):

name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used.

type: the field type, can be one of Text, Keyword, Long, Integer, Short, Byte, Double, Float, Half_Float, Scaled_Float, Date, Date_Nanos, Boolean, Binary, Integer_Range, Float_Range, Long_Range, Double_Range, Date_Range, Ip_Range, Object, Nested, Ip, TokenCount, Percolator, Flattened, Search_As_You_Type. See Elasticsearch Mapping Types

format and pattern custom definitions for the Date type.

store: Flag wether the original field value should be store in Elasticsearch, default value is false.

analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer.

@GeoPoint: marks a field as geo_point datatype. Can be omitted if the field is an instance of the GeoPoint class.

No comments:

Post a Comment