diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java index fd2c8f9bf9b..283f829d427 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java @@ -544,7 +544,7 @@ public class SearchRepository { searchClient.deleteByScript(indexMapping.getIndexName(clusterAlias), scriptTxt, params); } catch (Exception ie) { LOG.error( - "Issue in Creating new search document for entityType [{}]. Reason[{}], Cause[{}], Stack [{}]", + "Issue in deleting search document for entityType [{}]. Reason[{}], Cause[{}], Stack [{}]", entityType, ie.getMessage(), ie.getCause(), @@ -653,6 +653,16 @@ public class SearchRepository { new ImmutablePair<>( REMOVE_TAGS_CHILDREN_SCRIPT, Collections.singletonMap("fqn", entity.getFullyQualifiedName()))); + case Entity.DASHBOARD -> { + String scriptTxt = + String.format( + "if (ctx._source.dashboards.size() == 1) { ctx._source.put('deleted', '%s') }", + true); + searchClient.softDeleteOrRestoreChildren( + indexMapping.getChildAliases(clusterAlias), + scriptTxt, + List.of(new ImmutablePair<>("dashboards.id", docId))); + } case Entity.TEST_SUITE -> { TestSuite testSuite = (TestSuite) entity; if (Boolean.TRUE.equals(testSuite.getExecutable())) { @@ -701,6 +711,16 @@ public class SearchRepository { indexMapping.getChildAliases(clusterAlias), scriptTxt, List.of(new ImmutablePair<>("service.id", docId))); + case Entity.DASHBOARD -> { + scriptTxt = + String.format( + "if (ctx._source.dashboards.size() == 1) { ctx._source.put('deleted', '%s') }", + delete); + searchClient.softDeleteOrRestoreChildren( + indexMapping.getChildAliases(clusterAlias), + scriptTxt, + List.of(new ImmutablePair<>("dashboards.id", docId))); + } default -> searchClient.softDeleteOrRestoreChildren( indexMapping.getChildAliases(clusterAlias), scriptTxt, diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java index 0bff237df46..13743e81ae0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java @@ -1234,7 +1234,6 @@ public class OpenSearchClient implements SearchClient { @SneakyThrows public void updateSearch(UpdateRequest updateRequest) { if (updateRequest != null) { - updateRequest.docAsUpsert(true); updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); LOG.debug(SENDING_REQUEST_TO_ELASTIC_SEARCH, updateRequest); client.update(updateRequest, RequestOptions.DEFAULT); @@ -1650,6 +1649,7 @@ public class OpenSearchClient implements SearchClient { if (isClientAvailable) { UpdateRequest updateRequest = new UpdateRequest(indexName, docId); updateRequest.doc(doc, XContentType.JSON); + updateRequest.docAsUpsert(true); updateSearch(updateRequest); } } @@ -1659,6 +1659,7 @@ public class OpenSearchClient implements SearchClient { if (isClientAvailable) { UpdateRequest updateRequest = new UpdateRequest(indexName, docId); updateRequest.doc(doc, XContentType.JSON); + updateRequest.docAsUpsert(true); updateSearch(updateRequest); } }