From 52cbe1a39d16efec001c524b37deae5e38604bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Haarla=CC=88nder?= Date: Mon, 27 Nov 2023 17:15:29 +0100 Subject: [PATCH] Fixes for reindex --- .../mpg/imeji/logic/search/elasticsearch/ElasticIndexer.java | 2 +- .../search/elasticsearch/script/ItemPostIndexScript.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/ElasticIndexer.java b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/ElasticIndexer.java index 375bdf463..1875d09c5 100644 --- a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/ElasticIndexer.java +++ b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/ElasticIndexer.java @@ -101,7 +101,7 @@ public void updateIndexBatch(List objectList) try { LOGGER.info("+++ index request " + indexName + " " + getId(obj)); final IndexOperation indexOperation; - if (obj instanceof ResourceLastModified) { + if (obj instanceof ResourceLastModified && ((ResourceLastModified) obj).getModified() != null) { long timestamp = ((ResourceLastModified) obj).getModified().getTimeInMillis(); indexOperation = getIndexOperation(getId(obj), toJson(obj, dataType, indexName), getParent(obj), dataType, timestamp); } else { diff --git a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/script/ItemPostIndexScript.java b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/script/ItemPostIndexScript.java index 3dcb4609f..2a54821b7 100644 --- a/src/main/java/de/mpg/imeji/logic/search/elasticsearch/script/ItemPostIndexScript.java +++ b/src/main/java/de/mpg/imeji/logic/search/elasticsearch/script/ItemPostIndexScript.java @@ -36,9 +36,11 @@ public static void run(List list, String index) throws IOException, SearchInd List items = (List) list.stream().filter(o -> o instanceof Item).collect(Collectors.toList()); final BulkRequest.Builder bulkRequestBuilder = new BulkRequest.Builder(); + boolean fieldsFound = false; for (final Item item : items) { CollectionFields fields = retrieveCollectionFields(item, index); if (fields != null) { + fieldsFound = true; final ObjectNode json = fields.toJsonNode(); bulkRequestBuilder.operations(BulkOperation .of(bo -> bo.update(ur -> ur.index(ElasticIndices.items.name()).id(item.getId().toString()).action(act -> act.doc(json))))); @@ -46,8 +48,7 @@ public static void run(List list, String index) throws IOException, SearchInd } } - - if (items.size() > 0) { + if (fieldsFound) { final BulkRequest bulkRequest = bulkRequestBuilder.build(); BulkResponse bulkResponse = ElasticService.getClient().bulk(bulkRequest);