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-migration-guide-4.2-4.3.adoc
+1-2
Original file line number
Diff line number
Diff line change
@@ -11,5 +11,4 @@ This section describes breaking changes from version 4.2.x to 4.3.x and how remo
11
11
12
12
=== Handling of field and sourceFilter properties of Query
13
13
14
-
Up to version 4.2 the `fields` property of a `Query` was interpreted and added to the include list of the `sourceFilter`. This was not correct, as these are different things for Elasticsearch. This has been corrected. As a consequence code might not work anymore that relies on using `fields` to specify which fields should be returned from the document's
15
-
`_source' and should be changed to use the `sourceFilter`.
14
+
Up to version 4.2 the `fields` property of a `Query` was interpreted and added to the include list of the `sourceFilter`. This was not correct, as these are different things for Elasticsearch. This has been corrected. As a consequence code might not work anymore that relies on using `fields` to specify which fields should be returned from the document's `_source' and should be changed to use the `sourceFilter`.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/elasticsearch-object-mapping.adoc
+66-15
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,9 @@ Constructor arguments are mapped by name to the key values in the retrieved Docu
47
47
* `@Field`: Applied at the field level and defines properties of the field, most of the attributes map to the respective https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html[Elasticsearch Mapping] definitions (the following list is not complete, check the annotation Javadoc for a complete reference):
48
48
** `name`: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used.
49
49
** `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_.
50
-
See https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html[Elasticsearch Mapping Types]. If the field type is not specified, it defaults to `FieldType.Auto`. This means, that no mapping entry is written for the property and that Elasticsearch will add a mapping entry dynamically when the first data for this property is stored
51
-
(check the Elasticsearch documentation for dynamic mapping rules).
50
+
See https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html[Elasticsearch Mapping Types].
51
+
If the field type is not specified, it defaults to `FieldType.Auto`.
52
+
This means, that no mapping entry is written for the property and that Elasticsearch will add a mapping entry dynamically when the first data for this property is stored (check the Elasticsearch documentation for dynamic mapping rules).
52
53
** `format`: One or more built-in date formats, see the next section <<elasticsearch.mapping.meta-model.date-formats>>.
53
54
** `pattern`: One or more custom date formats, see the next section <<elasticsearch.mapping.meta-model.date-formats>>.
54
55
** `store`: Flag whether the original field value should be store in Elasticsearch, default value is _false_.
@@ -61,21 +62,20 @@ The mapping metadata infrastructure is defined in a separate spring-data-commons
61
62
[[elasticsearch.mapping.meta-model.date-formats]]
62
63
==== Date format mapping
63
64
64
-
Properties that derive from `TemporalAccessor` or are of type `java.util.Date` must either have a `@Field` annotation
65
-
of type `FieldType.Date` or a custom converter must be registered for this type. This paragraph describes the use of
65
+
Properties that derive from `TemporalAccessor` or are of type `java.util.Date` must either have a `@Field` annotation of type `FieldType.Date` or a custom converter must be registered for this type.
66
+
This paragraph describes the use of
66
67
`FieldType.Date`.
67
68
68
-
There are two attributes of the `@Field` annotation that define which date format information is written to the
69
-
mapping (also see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#built-in-date-formats[Elasticsearch Built In Formats] and https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#custom-date-formats[Elasticsearch Custom Date Formats])
69
+
There are two attributes of the `@Field` annotation that define which date format information is written to the mapping (also see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#built-in-date-formats[Elasticsearch Built In Formats] and https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#custom-date-formats[Elasticsearch Custom Date Formats])
70
70
71
-
The `format` attributes is used to define at least one of the predefined formats. If it is not defined, then a
72
-
default value of __date_optional_time_ and _epoch_millis_ is used.
71
+
The `format` attributes is used to define at least one of the predefined formats.
72
+
If it is not defined, then a default value of __date_optional_time_ and _epoch_millis_ is used.
73
73
74
-
The `pattern` attribute can be used to add additional custom format strings. If you want to use only custom date formats, you must set the `format` property to empty `{}`.
74
+
The `pattern` attribute can be used to add additional custom format strings.
75
+
If you want to use only custom date formats, you must set the `format` property to empty `{}`.
75
76
76
77
The following table shows the different attributes and the mapping created from their values:
77
78
78
-
79
79
[cols=2*,options=header]
80
80
|===
81
81
| annotation
@@ -101,12 +101,59 @@ The following table shows the different attributes and the mapping created from
101
101
NOTE: If you are using a custom date format, you need to use _uuuu_ for the year instead of _yyyy_.
102
102
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].
103
103
104
+
==== Range types
105
+
106
+
When a field is annotated with a type of one of _Integer_Range, Float_Range, Long_Range, Double_Range, Date_Range,_ or _Ip_Range_ the field must be an instance of a class that will be mapped to an Elasticsearch range, for example:
107
+
108
+
====
109
+
[source,java]
110
+
----
111
+
class SomePersonData {
112
+
113
+
@Field(type = FieldType.Integer_Range)
114
+
private ValidAge validAge;
115
+
116
+
// getter and setter
117
+
}
118
+
119
+
class ValidAge {
120
+
@Field(name="gte")
121
+
private Integer from;
122
+
123
+
@Field(name="lte")
124
+
private Integer to;
125
+
126
+
// getter and setter
127
+
}
128
+
----
129
+
====
130
+
131
+
As an alternative Spring Data Elasticsearch provides a `Range<T>` class so that the previous example can be written as:
132
+
133
+
====
134
+
[source,java]
135
+
----
136
+
class SomePersonData {
137
+
138
+
@Field(type = FieldType.Integer_Range)
139
+
private Range<Integer> validAge;
140
+
141
+
// getter and setter
142
+
}
143
+
----
144
+
====
145
+
146
+
Supported classes for the type `<T>` are `Integer`, `Long`, `Float`, `Double`, `Date` and classes that implement the
147
+
`TemporalAccessor` interface.
148
+
104
149
==== Mapped field names
105
150
106
-
Without further configuration, Spring Data Elasticsearch will use the property name of an object as field name in Elasticsearch. This can be changed for individual field by using the `@Field` annotation on that property.
151
+
Without further configuration, Spring Data Elasticsearch will use the property name of an object as field name in Elasticsearch.
152
+
This can be changed for individual field by using the `@Field` annotation on that property.
107
153
108
-
It is also possible to define a `FieldNamingStrategy` in the configuration of the client (<<elasticsearch.clients>>). If for example a `SnakeCaseFieldNamingStrategy` is configured, the property _sampleProperty_ of the object would be mapped to _sample_property_ in Elasticsearch. A `FieldNamingStrategy` applies to all entities; it can be overwritten by
109
-
setting a specific name with `@Field` on a property.
154
+
It is also possible to define a `FieldNamingStrategy` in the configuration of the client (<<elasticsearch.clients>>).
155
+
If for example a `SnakeCaseFieldNamingStrategy` is configured, the property _sampleProperty_ of the object would be mapped to _sample_property_ in Elasticsearch.
156
+
A `FieldNamingStrategy` applies to all entities; it can be overwritten by setting a specific name with `@Field` on a property.
110
157
111
158
[[elasticsearch.mapping.meta-model.rules]]
112
159
=== Mapping Rules
@@ -171,19 +218,23 @@ NOTE: Type hints will not be written for nested Objects unless the properties ty
171
218
172
219
===== Disabling Type Hints
173
220
174
-
It may be necessary to disable writing of type hints when the index that should be used already exists without having the type hints defined in its mapping and with the mapping mode set to strict. In this case, writing the type hint will produce an error, as the field cannot be added automatically.
221
+
It may be necessary to disable writing of type hints when the index that should be used already exists without having the type hints defined in its mapping and with the mapping mode set to strict.
222
+
In this case, writing the type hint will produce an error, as the field cannot be added automatically.
175
223
176
224
Type hints can be disabled for the whole application by overriding the method `writeTypeHints()` in a configuration class derived from `AbstractElasticsearchConfiguration` (see <<elasticsearch.clients>>).
177
225
178
226
As an alternativ they can be disabled for a single index with the `@Document` annotation:
WARNING: We strongly advise against disabling Type Hints. Only do this if you are forced to. Disabling type hints can lead to documents not being retrieved correctly from Elasticsearch in case of polymorphic data or document retrieval may fail completely.
235
+
WARNING: We strongly advise against disabling Type Hints.
236
+
Only do this if you are forced to.
237
+
Disabling type hints can lead to documents not being retrieved correctly from Elasticsearch in case of polymorphic data or document retrieval may fail completely.
Copy file name to clipboardExpand all lines: src/test/java/org/springframework/data/elasticsearch/core/convert/MappingElasticsearchConverterUnitTests.java
+1-2
Original file line number
Diff line number
Diff line change
@@ -2275,8 +2275,7 @@ public void setSaved(@Nullable String saved) {
0 commit comments