You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/elasticsearch-object-mapping.adoc
+38-28
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
[[elasticsearch.mapping]]
2
2
= Elasticsearch Object Mapping
3
3
4
-
Spring Data Elasticsearch Object Mapping is the process that maps a Java object - the domain entity - into the JSON
5
-
representation that is stored in Elasticsearch and back. The class that is internally used for this mapping is the
4
+
Spring Data Elasticsearch Object Mapping is the process that maps a Java object - the domain entity - into the JSON representation that is stored in Elasticsearch and back.
5
+
The class that is internally used for this mapping is the
6
6
`MappingElasticsearcvhConverter`.
7
7
8
8
[[elasticsearch.mapping.meta-model]]
@@ -52,21 +52,15 @@ The mapping metadata infrastructure is defined in a separate spring-data-commons
==== Controlling which properties are written to and read from Elasticsearch
54
54
55
-
This section details the annotations that define if the value of a property is written to or
56
-
read from Elasticsearch.
55
+
This section details the annotations that define if the value of a property is written to or read from Elasticsearch.
57
56
58
-
`@Transient`: A property annotated with this annotation will not be written to the mapping, it's value will not be
59
-
sent to Elasticsearch and when documents are returned from Elasticsearch, this property will not be set in the
60
-
resulting entity.
57
+
`@Transient`: A property annotated with this annotation will not be written to the mapping, it's value will not be sent to Elasticsearch and when documents are returned from Elasticsearch, this property will not be set in the resulting entity.
61
58
62
-
`@ReadOnlyProperty`: A property with this annotaiton will not have its value written to Elasticsearch, but when
63
-
returning data, the proeprty will be filled with the value returned in the document from Elasticsearch. One use case
64
-
for this are runtime fields defined in the index mapping.
65
-
66
-
`@WriteOnlyProperty`: A property with this annotaiton will have its value stored in Elasticsearch but will not be set
67
-
with any value when reading document. This can be used for example for synthesized fields which should go into the
68
-
Elasticsearch index but are not used elsewhere.
59
+
`@ReadOnlyProperty`: A property with this annotaiton will not have its value written to Elasticsearch, but when returning data, the proeprty will be filled with the value returned in the document from Elasticsearch.
60
+
One use case for this are runtime fields defined in the index mapping.
69
61
62
+
`@WriteOnlyProperty`: A property with this annotaiton will have its value stored in Elasticsearch but will not be set with any value when reading document.
63
+
This can be used for example for synthesized fields which should go into the Elasticsearch index but are not used elsewhere.
@@ -110,8 +104,7 @@ The following table shows the different attributes and the mapping created from
110
104
NOTE: If you are using a custom date format, you need to use _uuuu_ for the year instead of _yyyy_.
111
105
This is due to a https://www.elastic.co/guide/en/elasticsearch/reference/current/migrate-to-java-time.html#java-time-migration-incompatible-date-formats[change in Elasticsearch 7].
112
106
113
-
Check the code of the `org.springframework.data.elasticsearch.annotations.DateFormat` enum for a complete list of
114
-
predefined values and their patterns.
107
+
Check the code of the `org.springframework.data.elasticsearch.annotations.DateFormat` enum for a complete list of predefined values and their patterns.
Normally the properties used in an entity are fields of the entity class. There might be cases, when a property value
176
-
is calculated in the entity and should be stored in Elasticsearch. In this case, the getter method (`getProperty()`) can be
177
-
annotated
178
-
with the `@Field` annotation, in addition to that the method must be annotated with `@AccessType(AccessType.Type
179
-
.PROPERTY)`. The third annotation that is needed in such a case is `@WriteOnlyProperty`, as such a value is only
180
-
written to Elasticsearch. A full example:
168
+
Normally the properties used in an entity are fields of the entity class.
169
+
There might be cases, when a property value is calculated in the entity and should be stored in Elasticsearch.
170
+
In this case, the getter method (`getProperty()`) can be annotated with the `@Field` annotation, in addition to that the method must be annotated with `@AccessType(AccessType.Type
171
+
.PROPERTY)`.
172
+
The third annotation that is needed in such a case is `@WriteOnlyProperty`, as such a value is only written to Elasticsearch.
173
+
A full example:
174
+
181
175
====
182
176
[source,java]
183
177
----
@@ -190,6 +184,19 @@ public String getProperty() {
This annotation can be set on a String property of an entity.
193
+
This property will not be written to the mapping, it will not be stored in Elasticsearch and its value will not be read from an Elasticsearch document.
194
+
After an entity is persisted, for example with a call to `ElasticsearchOperations.save(T entity)`, the entity
195
+
returned from that call will contain the name of the index that an entity was saved to in that property.
196
+
This is useful when the index name is dynamically set by a bean, or when writing to a write alias.
197
+
198
+
Putting some value into such a property does not set the index into which an entity is stored!
199
+
193
200
[[elasticsearch.mapping.meta-model.rules]]
194
201
=== Mapping Rules
195
202
@@ -412,12 +419,15 @@ Looking at the `Configuration` from the <<elasticsearch.mapping.meta-model, prev
412
419
[source,java]
413
420
----
414
421
@Configuration
415
-
public class Config extends AbstractElasticsearchConfiguration {
422
+
public class Config extends ElasticsearchConfiguration {
416
423
417
-
@Override
418
-
public RestHighLevelClient elasticsearchClient() {
0 commit comments