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-clients.adoc
+58-34Lines changed: 58 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,10 @@
3
3
4
4
This chapter illustrates configuration and usage of supported Elasticsearch client implementations.
5
5
6
-
Spring Data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster.
7
-
Although the Elasticsearch Client can be used to work with the cluster, applications using Spring Data Elasticsearch normally use the higher level abstractions of <<elasticsearch.operations>> and <<elasticsearch.repositories>>.
6
+
Spring Data Elasticsearch operates upon an Elasticsearch client (provided by Elasticsearch client libraries) that is
7
+
connected to a single Elasticsearch node or a cluster.
8
+
Although the Elasticsearch Client can be used directly to work with the cluster, applications using Spring Data
9
+
Elasticsearch normally use the higher level abstractions of <<elasticsearch.operations>> and <<elasticsearch.repositories>>.
8
10
9
11
[[elasticsearch.clients.restclient]]
10
12
== Imperative Rest Client
@@ -21,14 +23,20 @@ public class MyClientConfig extends ElasticsearchConfiguration {
21
23
22
24
@Override
23
25
public ClientConfiguration clientConfiguration() {
24
-
return ClientConfiguration.builder() //
25
-
.connectedTo("localhost:9200") //
26
+
return ClientConfiguration.builder() <.>
27
+
.connectedTo("localhost:9200")
26
28
.build();
27
29
}
28
30
}
31
+
----
32
+
<.> for a detailed description of the builder methods see <<elasticsearch.clients.configuration>>
33
+
====
29
34
30
-
// ...
35
+
The following beans can then be injected in other Spring components:
<1> Use the builder to provide cluster addresses, set default `HttpHeaders` or enable SSL.
@@ -150,8 +158,12 @@ The `org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchCl
150
158
It uses the request/response objects provided by the Elasticsearch core project.
151
159
Calls are directly operated on the reactive stack, **not** wrapping async (thread pool bound) responses into reactive types.
152
160
153
-
This was the first reactive implementation Spring Data Elasticsearch provided, but now is deprecated in favour of the `org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient`
161
+
[CAUTION]
162
+
====
163
+
This was the first reactive implementation Spring Data Elasticsearch provided, but now is deprecated in favour
164
+
of the `org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient`
154
165
which uses the functionality offered by the new Elasticsearch client libraries.
166
+
====
155
167
156
168
.Reactive REST Client (deprecated)
157
169
====
@@ -194,6 +206,11 @@ Client behaviour can be changed via the `ClientConfiguration` that allows to set
<.> Optionally set a path prefix, mostly used when different clusters a behind some reverse proxy.
229
246
<.> Set the connection timeout.
230
-
Default is 10 sec.
231
247
<.> Set the socket timeout.
232
-
Default is 5 sec.
233
248
<.> Optionally set headers.
234
249
<.> Add basic authentication.
235
-
<.> A `Supplier<Header>` function can be specified which is called every time before a request is sent to Elasticsearch - here, as an example, the current time is written in a header.
250
+
<.> A `Supplier<HttpHeaders>` function can be specified which is called every time before a request is sent to Elasticsearch - here, as an example, the current time is written in a header.
236
251
<.> a function to configure the created client (see <<elasticsearch.clients.configuration.callbacks>>), can be added
237
252
multiple times.
238
253
====
@@ -251,6 +266,8 @@ The following callbacks are provided:
To see what is actually sent to and received from the server `Request` / `Response` logging on the transport level needs to be turned on as outlined in the snippet below.
336
+
To see what is actually sent to and received from the server `Request` / `Response` logging on the transport level
337
+
needs to be turned on as outlined in the snippet below. This can be enabled in the Elasticsearch client by setting
NOTE: The above applies to both the `RestHighLevelClient` and `ReactiveElasticsearchClient` when obtained via `RestClients` respectively `ReactiveRestClients`.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/elasticsearch-object-mapping.adoc
+8-19Lines changed: 8 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,9 @@
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 representation that is stored in Elasticsearch and back.
5
-
6
-
Earlier versions of Spring Data Elasticsearch used a Jackson based conversion, Spring Data Elasticsearch 3.2.x introduced the <<elasticsearch.mapping.meta-model>>.
7
-
As of version 4.0 only the Meta Object Mapping is used, the Jackson based mapper is not available anymore and the `MappingElasticsearchConverter` is used.
8
-
9
-
The main reasons for the removal of the Jackson based mapper are:
10
-
11
-
* Custom mappings of fields needed to be done with annotations like `@JsonFormat` or `@JsonInclude`.
12
-
This often caused problems when the same object was used in different JSON based datastores or sent over a JSON based API.
13
-
* Custom field types and formats also need to be stored into the Elasticsearch index mappings.
14
-
The Jackson based annotations did not fully provide all the information that is necessary to represent the types of Elasticsearch.
15
-
* Fields must be mapped not only when converting from and to entities, but also in query argument, returned data and on other places.
16
-
17
-
Using the `MappingElasticsearchConverter` now covers all these cases.
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
6
+
`MappingElasticsearcvhConverter`.
18
7
19
8
[[elasticsearch.mapping.meta-model]]
20
9
== Meta Model Object Mapping
@@ -31,14 +20,13 @@ The metadata is taken from the entity's properties which can be annotated.
31
20
The following annotations are available:
32
21
33
22
* `@Document`: Applied at the class level to indicate this class is a candidate for mapping to the database.
34
-
The most important attributes are:
23
+
The most important attributes are (check the API documentation for the complete list of attributes):
35
24
** `indexName`: the name of the index to store this entity in.
36
25
This can contain a SpEL template expression like `"log-#{T(java.time.LocalDate).now().toString()}"`
37
26
** `createIndex`: flag whether to create an index on repository bootstrapping.
38
27
Default value is _true_.
39
28
See <<elasticsearch.repositories.autocreation>>
40
-
** `versionType`: Configuration of version management.
41
-
Default value is _EXTERNAL_.
29
+
42
30
43
31
* `@Id`: Applied at the field level to mark the field used for identity purpose.
44
32
* `@Transient`: By default all fields are mapped to the document when it is stored or retrieved, this annotation excludes the field.
@@ -103,6 +91,9 @@ The following table shows the different attributes and the mapping created from
103
91
NOTE: If you are using a custom date format, you need to use _uuuu_ for the year instead of _yyyy_.
104
92
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].
105
93
94
+
Check the code of the `org.springframework.data.elasticsearch.annotations.DateFormat` enum for a complete list of
0 commit comments