From ddf4f13c22acd19716f4df40338fce85c36ad4ef Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Mon, 6 Dec 2021 12:17:24 -0800 Subject: [PATCH] Fix #1563: Filter by database name (#1580) --- .../catalog/resources/search/SearchResource.java | 15 ++++----------- .../elasticsearch/table_index_mapping.json | 2 +- .../ingestion/sink/elasticsearch_constants.py | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/search/SearchResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/search/SearchResource.java index 1d5e292f87c..b4a9763cbe9 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/search/SearchResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/search/SearchResource.java @@ -14,12 +14,6 @@ package org.openmetadata.catalog.resources.search; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.SuggestBuilder; @@ -32,11 +26,9 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import org.apache.http.HttpHost; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilders; @@ -79,7 +71,7 @@ public class SearchResource { description = "Search entities using query test. Use query params `from` and `size` for pagination. Use " + "`sort_field` to sort the results in `sort_order`.", responses = { - @ApiResponse(responseCode = "200", description = "search response", + @ApiResponse(responseCode = "200", description = "search response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SearchResponse.class))) }) @@ -148,7 +140,7 @@ public class SearchResource { @Operation(summary = "Suggest entities", tags = "search", description = "Get suggested entities used for auto-completion.", responses = { - @ApiResponse(responseCode = "200", + @ApiResponse(responseCode = "200", description = "Table Suggestion API", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SearchResponse.class))) @@ -225,10 +217,11 @@ public class SearchResource { .aggregation(AggregationBuilders.terms("EntityType").field("entity_type")) .aggregation(AggregationBuilders.terms("Tier").field("tier")) .aggregation(AggregationBuilders.terms("Tags").field("tags")) + .aggregation(AggregationBuilders.terms("Database").field("database")) .highlighter(hb) .from(from).size(size); - return searchSourceBuilder; + return searchSourceBuilder; } private SearchSourceBuilder buildTopicSearchBuilder(String query, int from, int size) { diff --git a/catalog-rest-service/src/main/resources/elasticsearch/table_index_mapping.json b/catalog-rest-service/src/main/resources/elasticsearch/table_index_mapping.json index 7f9c2f52ea6..3d3c35d16a9 100644 --- a/catalog-rest-service/src/main/resources/elasticsearch/table_index_mapping.json +++ b/catalog-rest-service/src/main/resources/elasticsearch/table_index_mapping.json @@ -47,7 +47,7 @@ "type": "keyword" }, "database": { - "type": "text" + "type": "keyword" }, "suggest": { "type": "completion" diff --git a/ingestion/src/metadata/ingestion/sink/elasticsearch_constants.py b/ingestion/src/metadata/ingestion/sink/elasticsearch_constants.py index b954d9c86e9..bd140beac46 100644 --- a/ingestion/src/metadata/ingestion/sink/elasticsearch_constants.py +++ b/ingestion/src/metadata/ingestion/sink/elasticsearch_constants.py @@ -63,7 +63,7 @@ TABLE_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent( "type": "keyword" }, "database": { - "type": "text" + "type": "keyword" }, "suggest": { "type": "completion"