diff --git a/indexing-handlers/src/main/resources/import_candidates_mappings.json b/indexing-handlers/src/main/resources/import_candidates_mappings.json index 08438c3d9..6b8a73f77 100644 --- a/indexing-handlers/src/main/resources/import_candidates_mappings.json +++ b/indexing-handlers/src/main/resources/import_candidates_mappings.json @@ -1,7 +1,8 @@ { "properties": { "publicationInstance": { - "type": "nested" + "type": "nested", + "include_in_parent": true }, "organizations": { "type": "nested", @@ -12,7 +13,10 @@ } }, "associatedArtifacts": { - "type": "nested" + "type": "nested", + "include_in_parent": true } } -} \ No newline at end of file +} + + diff --git a/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java b/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java index 788656445..3152e9bf1 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java +++ b/search-commons/src/main/java/no/unit/nva/search2/constant/ApplicationConstants.java @@ -149,11 +149,8 @@ public static String readApiHost() { generateSimpleAggregation(INSTANCE_TYPE, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_INSTANCE_TYPE_KEYWORD), generateSimpleAggregation(CONTEXT_TYPE, ENTITY_DESCRIPTION_REFERENCE_PUBLICATION_CONTEXT_TYPE_KEYWORD), generateFundingSourceAggregation(), - generateTopLevelOrganizationAggregation2(), - // generateSimpleAggregation(ASSOCIATED_ARTIFACTS, ASSOCIATED_ARTIFACTS + DOT + TYPE + DOT + KEYWORD)., -// generateHasFileAggregation(), - generateObjectLabelsAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS) - // generateIdAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS) + generateObjectLabelsAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS), + generateHasFileAggregation() ); private static TermsAggregationBuilder generateSimpleAggregation(String term, String field) { @@ -175,27 +172,6 @@ private static TermsAggregationBuilder generateFundingSourceAggregation() { generateLabelsAggregation(jsonPath(FUNDINGS, SOURCE))); } - private static TermsAggregationBuilder generateTopLevelOrganizationAggregation2() { - return - generateSimpleAggregation(TOP_LEVEL_ORGANIZATION, TOP_LEVEL_ORGANIZATIONS + DOT + ID + DOT + KEYWORD) - .subAggregation( - generateLabelsAggregation(TOP_LEVEL_ORGANIZATIONS)); - } - - private static NestedAggregationBuilder generateTopLevelAggregation() { - return - new NestedAggregationBuilder("test1", jsonPath(TOP_LEVEL_ORGANIZATIONS)) - // .subAggregation( - .subAggregation(generateLabelsAggregation(jsonPath(TOP_LEVEL_ORGANIZATIONS))); - } - - private static TermsAggregationBuilder generateTopLevelOrganizationAggregation() { - return - new TermsAggregationBuilder("test2") - .field(jsonPath(TOP_LEVEL_ORGANIZATIONS, ID, KEYWORD)) - .subAggregation(generateLabelsAggregation(jsonPath(TOP_LEVEL_ORGANIZATIONS)) - ); - } private static TermsAggregationBuilder generateIdAggregation(String object) { return new TermsAggregationBuilder(ID) @@ -204,11 +180,6 @@ private static TermsAggregationBuilder generateIdAggregation(String object) { .subAggregation(generateLabelsAggregation(object)); } - // private static TermsAggregationBuilder generateIdAggregation(String displayName, String path) { - // return generateSimpleAggregation(displayName, jsonPath(path, ID, KEYWORD)) - // .size(Defaults.DEFAULT_AGGREGATION_SIZE) -// .subAggregation(generateLabelsAggregation(path)); - // } private static NestedAggregationBuilder generateLabelsAggregation(String jsonPath) { var nestedAggregation = new NestedAggregationBuilder(LABELS, jsonPath(jsonPath, LABELS)); diff --git a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java b/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java index 35d71febf..42b215775 100644 --- a/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java +++ b/search-commons/src/main/java/no/unit/nva/search2/model/opensearch/SwsResponse.java @@ -114,17 +114,18 @@ public static JsonNode formatAggregations(JsonNode aggregations) { .orElse(fieldName.replaceFirst(WORD_ENDING_WITH_HASHTAG_REGEX, "")); var value = nodeEntry.getValue(); + if (value.at("/id/buckets").isArray()) { + value = value.at("/id/buckets"); + } + if (value.has("buckets")) { + value = value.at("/buckets"); + } if (LABELS.equals(newName)) { outputAggregationNode.set(newName, formatLabels(value)); } else if (NAME.equals(newName)) { outputAggregationNode.set(LABELS, formatName(value)); } else if (value.isValueNode()) { outputAggregationNode.set(newName, value); - } else if (value.has("buckets")) { - var bucket = value.get("buckets"); - var arrayNode = objectMapperWithEmpty.createArrayNode(); - bucket.forEach(element -> arrayNode.add(formatAggregations(element))); - outputAggregationNode.set(newName, arrayNode); } else if (value.isArray()) { var arrayNode = objectMapperWithEmpty.createArrayNode(); value.forEach(element -> arrayNode.add(formatAggregations(element))); diff --git a/search-commons/src/test/java/no/unit/nva/search/OpensearchTest.java b/search-commons/src/test/java/no/unit/nva/search/OpensearchTest.java index 66195aea7..bf7845855 100644 --- a/search-commons/src/test/java/no/unit/nva/search/OpensearchTest.java +++ b/search-commons/src/test/java/no/unit/nva/search/OpensearchTest.java @@ -251,7 +251,7 @@ void shouldReturnInstanceTypeAggregationWithDocCountTwo() var query = queryWithTermAndAggregation(SEARCH_ALL, IMPORT_CANDIDATES_AGGREGATIONS); var response = searchClient.searchWithSearchDocumentQuery(query, indexName); - var docCount = response.getAggregations().get("type").get("buckets").get(0).get("docCount").asInt(); + var docCount = response.getAggregations().get("instanceType").get("buckets").get(0).get("docCount").asInt(); assertThat(docCount, is(equalTo(1))); } @@ -261,8 +261,8 @@ void shouldFilterDocumentsWithFiles() addDocumentsToIndex("imported_candidate_from_index.json", "not_imported_candidate_from_index.json"); var query = queryWithTermAndAggregation( - "(associatedArtifacts.type:\"PublishedFile\")AND(associatedArtifacts.administrativeAgreement:\"false\")", - IMPORT_CANDIDATES_AGGREGATIONS); + "(associatedArtifacts.type:\"PublishedFile\")AND(associatedArtifacts" + + ".administrativeAgreement:\"false\")", IMPORT_CANDIDATES_AGGREGATIONS); var response = searchClient.searchWithSearchDocumentQuery(query, indexName); diff --git a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java index a9f1c5233..2f17a62bb 100644 --- a/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java +++ b/search-commons/src/test/java/no/unit/nva/search2/ResourceClientTest.java @@ -120,8 +120,8 @@ void searchWithUriReturnsOpenSearchAwsResponse(URI uri) throws ApiGatewayExcepti ) ); - assertThat(query.getValue(SIZE).as(), is(equalTo(pagedSearchResourceDto.hits().size()))); - assertThat(query.getValue(SIZE).as(), is(equalTo(pagedSearchResourceDto.totalHits()))); + assertThat(pagedSearchResourceDto.hits().size(), is(equalTo(query.getValue(SIZE).as()))); + assertThat(pagedSearchResourceDto.totalHits(), is(equalTo(query.getValue(SIZE).as()))); } @ParameterizedTest diff --git a/search-commons/src/test/resources/test_import_candidates_mappings.json b/search-commons/src/test/resources/test_import_candidates_mappings.json index 98c6d4da9..6b8a73f77 100644 --- a/search-commons/src/test/resources/test_import_candidates_mappings.json +++ b/search-commons/src/test/resources/test_import_candidates_mappings.json @@ -1,7 +1,8 @@ { "properties": { "publicationInstance": { - "type": "nested" + "type": "nested", + "include_in_parent": true }, "organizations": { "type": "nested", @@ -12,7 +13,8 @@ } }, "associatedArtifacts": { - "type": "nested" + "type": "nested", + "include_in_parent": true } } } diff --git a/search-commons/src/test/resources/test_resources_mappings.json b/search-commons/src/test/resources/test_resources_mappings.json index 19ebd8c5d..f158b2b59 100644 --- a/search-commons/src/test/resources/test_resources_mappings.json +++ b/search-commons/src/test/resources/test_resources_mappings.json @@ -2,10 +2,8 @@ "properties": { "topLevelOrganizations": { "type": "nested", - "include_in_parent": true, "properties": { "labels": { - "include_in_parent": true, "type": "nested" } }