Skip to content

Commit

Permalink
feat(search): Throw exception instead of returning an empty response …
Browse files Browse the repository at this point in the history
…from scroll in an error case (#8517)

Co-authored-by: Indy Prentice <[email protected]>
  • Loading branch information
iprentic and Indy Prentice authored Jul 29, 2023
1 parent e09a2e6 commit 55c6592
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Request;
Expand All @@ -44,7 +43,6 @@

import static com.linkedin.metadata.Constants.*;
import static com.linkedin.metadata.models.registry.template.util.TemplateUtil.*;
import static com.linkedin.metadata.search.utils.SearchUtils.*;
import static com.linkedin.metadata.utils.SearchUtil.*;


Expand Down Expand Up @@ -154,14 +152,6 @@ private ScrollResult executeAndExtract(@Nonnull List<EntitySpec> entitySpecs, @N
.extractScrollResult(searchResponse,
filter, scrollId, keepAlive, size, supportsPointInTime()));
} catch (Exception e) {
if (e instanceof ElasticsearchStatusException) {
final ElasticsearchStatusException statusException = (ElasticsearchStatusException) e;
if (statusException.status().getStatus() == 400) {
// Malformed query -- Could indicate bad search syntax. Return empty response.
log.warn("Received 400 from Elasticsearch. Returning empty search response", e);
return EMPTY_SCROLL_RESULT;
}
}
log.error("Search query failed", e);
throw new ESQueryException("Search query failed:", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.search.AggregationMetadata;
import com.linkedin.metadata.search.FilterValueArray;
import com.linkedin.metadata.search.ScrollResult;
import com.linkedin.metadata.search.SearchEntity;
import com.linkedin.metadata.search.SearchEntityArray;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.metadata.search.SearchResultMetadata;
import com.linkedin.metadata.utils.SearchUtil;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -39,19 +36,6 @@
@Slf4j
public class SearchUtils {

public static final SearchResult EMPTY_SEARCH_RESULT =
new SearchResult().setEntities(new SearchEntityArray(Collections.emptyList()))
.setMetadata(new SearchResultMetadata())
.setFrom(0)
.setPageSize(0)
.setNumEntities(0);

public static final ScrollResult EMPTY_SCROLL_RESULT =
new ScrollResult().setEntities(new SearchEntityArray(Collections.emptyList()))
.setMetadata(new SearchResultMetadata())
.setPageSize(0)
.setNumEntities(0);

private SearchUtils() {

}
Expand Down

0 comments on commit 55c6592

Please sign in to comment.