2626import java .util .LinkedHashMap ;
2727import java .util .Map ;
2828
29+ import org .elasticsearch .common .geo .GeoPoint ;
2930import org .junit .jupiter .api .AfterEach ;
3031import org .junit .jupiter .api .BeforeEach ;
3132import org .junit .jupiter .api .DisplayName ;
4041import org .springframework .data .elasticsearch .core .IndexOperations ;
4142import org .springframework .data .elasticsearch .core .SearchHits ;
4243import org .springframework .data .elasticsearch .core .convert .ElasticsearchCustomConversions ;
43- import org .springframework .data .elasticsearch .core .geo .GeoJsonPoint ;
4444import org .springframework .data .elasticsearch .core .query .Query ;
4545import org .springframework .data .elasticsearch .junit .jupiter .ElasticsearchRestTemplateConfiguration ;
4646import org .springframework .data .elasticsearch .junit .jupiter .SpringIntegrationTest ;
@@ -72,7 +72,7 @@ public ElasticsearchCustomConversions elasticsearchCustomConversions() {
7272 void setUp () {
7373 IndexOperations indexOps = operations .indexOps (Entity .class );
7474 indexOps .create ();
75- indexOps .putMapping ();
75+ indexOps .putMapping (indexOps . createMapping () );
7676 }
7777
7878 @ AfterEach
@@ -86,7 +86,7 @@ void shouldUseCustomConversionsOnEntity() {
8686
8787 Entity entity = Entity .builder () //
8888 .value ("hello" ) //
89- .location (GeoJsonPoint . of ( 8.0 , 42.7 )) //
89+ .location (new GeoPoint ( 42.7 , 8.0 )) //
9090 .build ();
9191
9292 org .springframework .data .elasticsearch .core .document .Document document = org .springframework .data .elasticsearch .core .document .Document
@@ -104,10 +104,11 @@ void shouldStoreAndLoadEntityFromElasticsearch() {
104104
105105 Entity entity = Entity .builder () //
106106 .value ("hello" ) //
107- .location (GeoJsonPoint . of ( 8.0 , 42.7 )) //
107+ .location (new GeoPoint ( 42.7 , 8.0 )) //
108108 .build ();
109109
110110 Entity savedEntity = operations .save (entity );
111+ operations .indexOps (Entity .class ).refresh ();
111112
112113 SearchHits <Entity > searchHits = operations .search (Query .findAll (), Entity .class );
113114 assertThat (searchHits .getTotalHits ()).isEqualTo (1 );
@@ -122,7 +123,7 @@ void shouldStoreAndLoadEntityFromElasticsearch() {
122123 @ Document (indexName = "entity-with-custom-conversions" )
123124 static class Entity {
124125 private String value ;
125- private GeoJsonPoint location ;
126+ private GeoPoint location ;
126127 }
127128
128129 @ WritingConverter
@@ -131,8 +132,8 @@ static class EntityToMapConverter implements Converter<Entity, Map<String, Objec
131132 public Map <String , Object > convert (Entity source ) {
132133 LinkedHashMap <String , Object > target = new LinkedHashMap <>();
133134 target .put ("the_value" , source .getValue ());
134- target .put ("the_lat" , "" + source .getLocation ().getY ( ));
135- target .put ("the_lon" , "" + source .getLocation ().getX ( ));
135+ target .put ("the_lat" , String . valueOf ( source .getLocation ().getLat () ));
136+ target .put ("the_lon" , String . valueOf ( source .getLocation ().getLon () ));
136137 return target ;
137138 }
138139 }
@@ -144,10 +145,10 @@ static class MapToEntityConverter implements Converter<Map<String, Object>, Enti
144145 public Entity convert (Map <String , Object > source ) {
145146 Entity entity = new Entity ();
146147 entity .setValue ((String ) source .get ("the_value" ));
147- entity .setLocation (GeoJsonPoint . of ( //
148- Double .parseDouble ((String ) (source .get ("the_lon " ))), //
149- Double .parseDouble ((String ) (source .get ("the_lat " ))) //
150- ));
148+ entity .setLocation (new GeoPoint ( //
149+ Double .parseDouble ((String ) (source .get ("the_lat " ))), //
150+ Double .parseDouble ((String ) (source .get ("the_lon " ))) //
151+ ));
151152 return entity ;
152153 }
153154 }
0 commit comments