Skip to content

Commit da20cc1

Browse files
authored
DATAES-931 - Add query support for geo shape queries.
Original PR: spring-projects#542
1 parent 7198a02 commit da20cc1

16 files changed

+554
-220
lines changed

src/main/asciidoc/reference/elasticsearch-new.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
[[new-features.4-1-0]]
55
== New in Spring Data Elasticsearch 4.1
66

7-
* Upgrade to Elasticsearch 7.9.2
8-
* Improved API for alias management
9-
* Introduction of `ReactiveIndexOperations` for index management
10-
* Index templates support
7+
* Uses Spring 5.3.
8+
* Upgrade to Elasticsearch 7.9.2.
9+
* Improved API for alias management.
10+
* Introduction of `ReactiveIndexOperations` for index management.
11+
* Index templates support.
12+
* Support for Geo-shape data with GeoJson.
1113

1214
[[new-features.4-0-0]]
1315
== New in Spring Data Elasticsearch 4.0

src/main/asciidoc/reference/elasticsearch-object-mapping.adoc

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33

44
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.
55

6-
Earlier versions of Spring Data Elasticsearch used a Jackson based conversion, Spring Data Elasticsearch 3.2.x introduced the <<elasticsearch.mapping.meta-model>>. 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.
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.
78

89
The main reasons for the removal of the Jackson based mapper are:
910

10-
* Custom mappings of fields needed to be done with annotations like `@JsonFormat` or `@JsonInclude`. This often caused problems when the same object was used in different JSON based datastores or sent over a JSON based API.
11-
* Custom field types and formats also need to be stored into the Elasticsearch index mappings. The Jackson based annotations did not fully provide all the information that is necessary to represent the types of Elasticsearch.
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.
1215
* Fields must be mapped not only when converting from and to entities, but also in query argument, returned data and on other places.
1316

1417
Using the `MappingElasticsearchConverter` now covers all these cases.
1518

16-
1719
[[elasticsearch.mapping.meta-model]]
1820
== Meta Model Object Mapping
1921

@@ -23,33 +25,48 @@ This allows to register `Converter` instances for specific domain type mapping.
2325
[[elasticsearch.mapping.meta-model.annotations]]
2426
=== Mapping Annotation Overview
2527

26-
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.
28+
The `MappingElasticsearchConverter` uses metadata to drive the mapping of objects to documents.
29+
The metadata is taken from the entity's properties which can be annotated.
2730

2831
The following annotations are available:
2932

30-
* `@Document`: Applied at the class level to indicate this class is a candidate for mapping to the database. The most important attributes are:
31-
** `indexName`: the name of the index to store this entity in. This can contain a SpEL template expression like `"log-#{T(java.time.LocalDate).now().toString()}"`
32-
** `type`: [line-through]#the mapping type. If not set, the lowercased simple name of the class is used.# (deprecated since version 4.0)
33+
* `@Document`: Applied at the class level to indicate this class is a candidate for mapping to the database.
34+
The most important attributes are:
35+
** `indexName`: the name of the index to store this entity in.
36+
This can contain a SpEL template expression like `"log-#{T(java.time.LocalDate).now().toString()}"`
37+
** `type`: [line-through]#the mapping type.
38+
If not set, the lowercased simple name of the class is used.# (deprecated since version 4.0)
3339
** `shards`: the number of shards for the index.
3440
** `replicas`: the number of replicas for the index.
35-
** `refreshIntervall`: Refresh interval for the index. Used for index creation. Default value is _"1s"_.
36-
** `indexStoreType`: Index storage type for the index. Used for index creation. Default value is _"fs"_.
37-
** `createIndex`: flag whether to create an index on repository bootstrapping. Default value is _true_. See <<elasticsearch.repositories.autocreation>>
38-
** `versionType`: Configuration of version management. Default value is _EXTERNAL_.
41+
** `refreshIntervall`: Refresh interval for the index.
42+
Used for index creation.
43+
Default value is _"1s"_.
44+
** `indexStoreType`: Index storage type for the index.
45+
Used for index creation.
46+
Default value is _"fs"_.
47+
** `createIndex`: flag whether to create an index on repository bootstrapping.
48+
Default value is _true_.
49+
See <<elasticsearch.repositories.autocreation>>
50+
** `versionType`: Configuration of version management.
51+
Default value is _EXTERNAL_.
3952

4053
* `@Id`: Applied at the field level to mark the field used for identity purpose.
4154
* `@Transient`: By default all fields are mapped to the document when it is stored or retrieved, this annotation excludes the field.
42-
* `@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.
55+
* `@PersistenceConstructor`: Marks a given constructor - even a package protected one - to use when instantiating the object from the database.
56+
Constructor arguments are mapped by name to the key values in the retrieved Document.
4357
* `@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):
4458
** `name`: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used.
45-
** `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 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html[Elasticsearch Mapping Types]
59+
** `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_.
60+
See https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html[Elasticsearch Mapping Types]
4661
** `format` and `pattern` definitions for the _Date_ type. `format` must be defined for date types.
4762
** `store`: Flag whether the original field value should be store in Elasticsearch, default value is _false_.
4863
** `analyzer`, `searchAnalyzer`, `normalizer` for specifying custom analyzers and normalizer.
49-
* `@GeoPoint`: marks a field as _geo_point_ datatype. Can be omitted if the field is an instance of the `GeoPoint` class.
64+
* `@GeoPoint`: marks a field as _geo_point_ datatype.
65+
Can be omitted if the field is an instance of the `GeoPoint` class.
5066

5167
NOTE: Properties that derive from `TemporalAccessor` must either have a `@Field` annotation of type `FieldType.Date` or a custom converter must be registered for this type. +
52-
If you are using a custom date format, you need to use _uuuu_ for the year instead of _yyyy_. 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].
68+
If you are using a custom date format, you need to use _uuuu_ for the year instead of _yyyy_.
69+
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].
5370

5471
The mapping metadata infrastructure is defined in a separate spring-data-commons project that is technology agnostic.
5572

@@ -72,6 +89,7 @@ public class Person { <1>
7289
String lastname;
7390
}
7491
----
92+
7593
[source,json]
7694
----
7795
{
@@ -84,10 +102,10 @@ public class Person { <1>
84102
<1> By default the domain types class name is used for the type hint.
85103
====
86104

87-
Type hints can be configured to hold custom information. Use the `@TypeAlias` annotation to do so.
105+
Type hints can be configured to hold custom information.
106+
Use the `@TypeAlias` annotation to do so.
88107

89-
NOTE: Make sure to add types with `@TypeAlias` to the initial entity set (`AbstractElasticsearchConfiguration#getInitialEntitySet`)
90-
to already have entity information available when first reading data from the store.
108+
NOTE: Make sure to add types with `@TypeAlias` to the initial entity set (`AbstractElasticsearchConfiguration#getInitialEntitySet`) to already have entity information available when first reading data from the store.
91109

92110
.Type Hints with Alias
93111
====
@@ -100,6 +118,7 @@ public class Person {
100118
// ...
101119
}
102120
----
121+
103122
[source,json]
104123
----
105124
{
@@ -126,6 +145,7 @@ public class Address {
126145
Point location;
127146
}
128147
----
148+
129149
[source,json]
130150
----
131151
{
@@ -138,8 +158,9 @@ public class Address {
138158

139159
==== GeoJson Types
140160

141-
Spring Data Elasticsearch supports the GeoJson types by providing an interface `GeoJson` and implementations for the different geometries. They are mapped to Elasticsearch
142-
documents according to the GeoJson specification. The corresponding properties of the entity are specified as `geo_shape` when the index mappings is written.
161+
Spring Data Elasticsearch supports the GeoJson types by providing an interface `GeoJson` and implementations for the different geometries.
162+
They are mapped to Elasticsearch documents according to the GeoJson specification.
163+
The corresponding properties of the entity are specified in the index mappings as `geo_shape` when the index mappings is written. (check the https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html[Elasticsearch documentation] as well)
143164

144165
.GeoJson types
145166
====
@@ -151,6 +172,7 @@ public class Address {
151172
GeoJsonPoint location;
152173
}
153174
----
175+
154176
[source,json]
155177
----
156178
{
@@ -190,6 +212,7 @@ public class Person {
190212
191213
}
192214
----
215+
193216
[source,json]
194217
----
195218
{
@@ -217,6 +240,7 @@ public class Person {
217240
218241
}
219242
----
243+
220244
[source,json]
221245
----
222246
{
@@ -283,6 +307,7 @@ public class Config extends AbstractElasticsearchConfiguration {
283307
}
284308
}
285309
----
310+
286311
[source,json]
287312
----
288313
{

0 commit comments

Comments
 (0)