Skip to content

Commit

Permalink
WARN on 400 from elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoyce0510 committed Feb 18, 2022
1 parent b08784e commit ed2f355
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/home/HomePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export const HomePageHeader = () => {
onClick={() =>
navigateToSearchUrl({
type: undefined,
query: suggestion,
query: `"${suggestion}"`,
history,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchEntityArray;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.metadata.search.SearchResultMetadata;
import com.linkedin.metadata.search.elasticsearch.query.request.AutocompleteRequestHandler;
import com.linkedin.metadata.search.elasticsearch.query.request.SearchRequestHandler;
import com.linkedin.metadata.utils.elasticsearch.IndexConvention;
import com.linkedin.metadata.utils.metrics.MetricUtils;
import io.opentelemetry.extension.annotations.WithSpan;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import javax.annotation.Nonnull;
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.RequestOptions;
Expand All @@ -33,10 +37,17 @@
@RequiredArgsConstructor
public class ESSearchDAO {

private static final SearchResult EMPTY_SEARCH_RESULT = new SearchResult().setEntities(new SearchEntityArray(
Collections.emptyList()))
.setMetadata(new SearchResultMetadata())
.setFrom(0)
.setPageSize(0)
.setNumEntities(0);
private final EntityRegistry entityRegistry;
private final RestHighLevelClient client;
private final IndexConvention indexConvention;


public long docCount(@Nonnull String entityName) {
EntitySpec entitySpec = entityRegistry.getEntitySpec(entityName);
CountRequest countRequest =
Expand All @@ -58,6 +69,14 @@ private SearchResult executeAndExtract(@Nonnull EntitySpec entitySpec, @Nonnull
// extract results, validated against document model as well
return SearchRequestHandler.getBuilder(entitySpec).extractResult(searchResponse, from, size);
} 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_SEARCH_RESULT;
}
}
log.error("Search query failed", e);
throw new ESQueryException("Search query failed:", e);
}
Expand Down

0 comments on commit ed2f355

Please sign in to comment.