Search in sources :

Example 1 with ExplainRequestBuilder

use of org.elasticsearch.action.explain.ExplainRequestBuilder in project molgenis by molgenis.

the class ClientFacade method explain.

public Explanation explain(SearchHit searchHit, QueryBuilder query) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Explaining doc with id '{}' in index '{}' for query '{}' ...", searchHit.getId(), searchHit.getIndex(), query);
    }
    String indexName = searchHit.getIndex();
    // FIXME: ClientFacade shouldn't assume that typename equals typename
    ExplainRequestBuilder explainRequestBuilder = client.prepareExplain(indexName, indexName, searchHit.getId()).setQuery(query);
    ExplainResponse explainResponse;
    try {
        explainResponse = explainRequestBuilder.get();
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error explaining doc with id '%s' in index '%s' for query '%s'.", searchHit.getId(), searchHit.getIndex(), query));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Explained doc with id '{}' in index '{}' for query.", searchHit.getId(), searchHit.getIndex(), query);
    }
    return explainResponse.getExplanation();
}
Also used : IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ExplainResponse(org.elasticsearch.action.explain.ExplainResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException) ExplainRequestBuilder(org.elasticsearch.action.explain.ExplainRequestBuilder)

Aggregations

ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ExplainRequestBuilder (org.elasticsearch.action.explain.ExplainRequestBuilder)1 ExplainResponse (org.elasticsearch.action.explain.ExplainResponse)1 IndexException (org.molgenis.data.index.exception.IndexException)1 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)1