|
40 | 40 | import org.springframework.data.elasticsearch.core.query.BaseQuery; |
41 | 41 | import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; |
42 | 42 | import org.springframework.data.elasticsearch.core.query.Query; |
| 43 | +import org.springframework.data.elasticsearch.core.routing.RoutingResolver; |
43 | 44 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; |
44 | 45 | import org.springframework.data.util.StreamUtils; |
45 | 46 | import org.springframework.data.util.Streamable; |
@@ -257,31 +258,31 @@ public void deleteById(ID id) { |
257 | 258 |
|
258 | 259 | Assert.notNull(id, "Cannot delete entity with id 'null'."); |
259 | 260 |
|
260 | | - doDelete(id, getIndexCoordinates()); |
| 261 | + doDelete(id, null, getIndexCoordinates()); |
261 | 262 | } |
262 | 263 |
|
263 | 264 | @Override |
264 | 265 | public void deleteById(ID id, @Nullable RefreshPolicy refreshPolicy) { |
265 | 266 |
|
266 | 267 | Assert.notNull(id, "Cannot delete entity with id 'null'."); |
267 | 268 |
|
268 | | - doDelete(id, getIndexCoordinates(), refreshPolicy); |
| 269 | + doDelete(id, null, getIndexCoordinates(), refreshPolicy); |
269 | 270 | } |
270 | 271 |
|
271 | 272 | @Override |
272 | 273 | public void delete(T entity) { |
273 | 274 |
|
274 | 275 | Assert.notNull(entity, "Cannot delete 'null' entity."); |
275 | 276 |
|
276 | | - doDelete(extractIdFromBean(entity), getIndexCoordinates()); |
| 277 | + doDelete(extractIdFromBean(entity), operations.getEntityRouting(entity), getIndexCoordinates()); |
277 | 278 | } |
278 | 279 |
|
279 | 280 | @Override |
280 | 281 | public void delete(T entity, @Nullable RefreshPolicy refreshPolicy) { |
281 | 282 |
|
282 | 283 | Assert.notNull(entity, "Cannot delete 'null' entity."); |
283 | 284 |
|
284 | | - doDelete(extractIdFromBean(entity), getIndexCoordinates(), refreshPolicy); |
| 285 | + doDelete(extractIdFromBean(entity), operations.getEntityRouting(entity), getIndexCoordinates(), refreshPolicy); |
285 | 286 | } |
286 | 287 |
|
287 | 288 | @Override |
@@ -352,17 +353,26 @@ private List<ID> getEntityIds(Iterable<? extends T> entities) { |
352 | 353 | return ids; |
353 | 354 | } |
354 | 355 |
|
355 | | - private void doDelete(@Nullable ID id, IndexCoordinates indexCoordinates) { |
| 356 | + private void doDelete(@Nullable ID id, @Nullable String routing, IndexCoordinates indexCoordinates) { |
356 | 357 |
|
357 | 358 | if (id != null) { |
358 | | - executeAndRefresh(operations -> operations.delete(stringIdRepresentation(id), indexCoordinates)); |
| 359 | + executeAndRefresh(operations -> { |
| 360 | + var ops = routing != null ? operations.withRouting(RoutingResolver.just(routing)) : operations; |
| 361 | + // noinspection DataFlowIssue |
| 362 | + return ops.delete(stringIdRepresentation(id), indexCoordinates); |
| 363 | + }); |
359 | 364 | } |
360 | 365 | } |
361 | 366 |
|
362 | | - private void doDelete(@Nullable ID id, IndexCoordinates indexCoordinates, @Nullable RefreshPolicy refreshPolicy) { |
| 367 | + private void doDelete(@Nullable ID id, @Nullable String routing, IndexCoordinates indexCoordinates, |
| 368 | + @Nullable RefreshPolicy refreshPolicy) { |
363 | 369 |
|
364 | 370 | if (id != null) { |
365 | | - executeAndRefresh(operations -> operations.delete(stringIdRepresentation(id), indexCoordinates), refreshPolicy); |
| 371 | + executeAndRefresh(operations -> { |
| 372 | + var ops = routing != null ? operations.withRouting(RoutingResolver.just(routing)) : operations; |
| 373 | + // noinspection DataFlowIssue |
| 374 | + return ops.delete(stringIdRepresentation(id), indexCoordinates); |
| 375 | + }, refreshPolicy); |
366 | 376 | } |
367 | 377 | } |
368 | 378 |
|
|
0 commit comments