@@ -166,6 +166,67 @@ Indexing multiple Document(bulk index) using Repository
166
166
repository. save(sampleEntities);
167
167
```
168
168
169
+ ### Adding custom behaviors to ResultMapper - CustomResultMapper
170
+
171
+ Define new class implementing ResultMapper
172
+
173
+ ``` java
174
+ public class CustomResultMapper implements ResultsMapper {
175
+
176
+ private EntityMapper entityMapper;
177
+
178
+ public CustomResultMapper (EntityMapper entityMapper ) {
179
+ this . entityMapper = entityMapper;
180
+ }
181
+
182
+ @Override
183
+ public EntityMapper getEntityMapper () {
184
+ return entityMapper;
185
+ }
186
+
187
+ @Override
188
+ public <T > T mapResult (GetResponse response , Class<T > clazz ) {
189
+ return null ; // Your implementation
190
+ }
191
+
192
+ @Override
193
+ public <T > FacetedPage<T > mapResults (SearchResponse response , Class<T > clazz , Pageable pageable ) {
194
+ return null ; // Your implementation
195
+ }
196
+ }
197
+
198
+ ```
199
+
200
+ Inject your custom implementation to template
201
+
202
+
203
+ ``` xml
204
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
205
+ <beans xmlns =" http://www.springframework.org/schema/beans"
206
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
207
+ xmlns : elasticsearch =" http://www.springframework.org/schema/data/elasticsearch"
208
+ xsi : schemaLocation =" http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
209
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" >
210
+
211
+ <elasticsearch : repositories base-package =" com.xyz.acme" />
212
+
213
+ <elasticsearch : transport-client id =" client" cluster-nodes =" localhost:9300,someip:9300" />
214
+
215
+ <bean name =" elasticsearchTemplate"
216
+ class =" org.springframework.data.elasticsearch.core.ElasticsearchTemplate" >
217
+ <constructor-arg name =" client" ref =" client" />
218
+ <constructor-arg name =" resultsMapper" ref =" resultMapper" />
219
+ </bean >
220
+
221
+ <bean name =" entityMapper" class =" org.springframework.data.elasticsearch.core.DefaultEntityMapper" />
222
+
223
+ <bean name =" resultMapper" class =" org.springframework.data.elasticsearch.core.CustomResultMapper" >
224
+ <constructor-arg ref =" entityMapper" />
225
+ </bean >
226
+
227
+ </beans >
228
+ ```
229
+
169
230
### Geo indexing and request
170
231
171
232
You can make request using geo_distance filter. This can be done using GeoPoint object.
0 commit comments