org.elasticsearch.action.search.SearchPhaseExecutionException Java Examples

The following examples show how to use org.elasticsearch.action.search.SearchPhaseExecutionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsIndex_searchメソッドで初回にSearchPhaseExecutionExceptionが投げられた場合のテスト.
 */
@Test
public void EsIndex_searchメソッドで初回にSearchPhaseExecutionExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsIndexImpl esIndexObject = Mockito.spy(new EsIndexImpl("dummy", "", 0, 0, null));

    // EsIndex#asyncIndexSearch()が呼ばれた場合に、SearchPhaseExecutionExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    SearchPhaseExecutionException toBeThrown = Mockito.mock(SearchPhaseExecutionException.class);
    Mockito.doThrow(toBeThrown)
            .when(esIndexObject)
            .asyncIndexSearch(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esIndexObject.search("dummyRoutingId", (Map<String, Object>) null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException e) {
        assertTrue(e.getCause() instanceof SearchPhaseExecutionException);
    }
}
 
Example #2
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_searchメソッドで初回にDcSearchPhaseExecutionExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_searchメソッドで初回にDcSearchPhaseExecutionExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncSearch()が呼ばれた場合に、SearchPhaseExecutionExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    SearchPhaseExecutionException toBeThrown = Mockito.mock(SearchPhaseExecutionException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.search(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException e) {
        assertTrue(e.getCause() instanceof DcSearchPhaseExecutionException);
    }
}
 
Example #3
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsIndex_searchメソッドで初回にSearchPhaseExecutionExceptionが投げられた場合のテスト.
 */
@Test
public void EsIndex_searchメソッドで初回にSearchPhaseExecutionExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsIndexImpl esIndexObject = Mockito.spy(new EsIndexImpl("dummy", "", 0, 0, null));

    // EsIndex#asyncIndexSearch()が呼ばれた場合に、SearchPhaseExecutionExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    SearchPhaseExecutionException toBeThrown = Mockito.mock(SearchPhaseExecutionException.class);
    Mockito.doThrow(toBeThrown)
            .when(esIndexObject)
            .asyncIndexSearch(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esIndexObject.search("dummyRoutingId", (Map<String, Object>) null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException e) {
        assertTrue(e.getCause() instanceof SearchPhaseExecutionException);
    }
}
 
Example #4
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_searchメソッドで初回にDcSearchPhaseExecutionExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_searchメソッドで初回にDcSearchPhaseExecutionExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncSearch()が呼ばれた場合に、SearchPhaseExecutionExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    SearchPhaseExecutionException toBeThrown = Mockito.mock(SearchPhaseExecutionException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.search(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException e) {
        assertTrue(e.getCause() instanceof DcSearchPhaseExecutionException);
    }
}
 
Example #5
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
MultiSearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #6
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        return null;
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #7
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        return null;
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #8
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
MultiSearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #9
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
MultiSearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #10
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexNotFoundException || e.getCause() instanceof IndexNotFoundException) {
        return new DcNullSearchResponse();
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", new DcSearchPhaseExecutionException(e));
    }
    throw e;
}
 
Example #11
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        return new DcNullSearchResponse();
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", new DcSearchPhaseExecutionException(e));
    }
    throw e;
}
 
Example #12
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
MultiSearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #13
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexNotFoundException || e.getCause() instanceof IndexNotFoundException) {
        return null;
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #14
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
SearchResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexNotFoundException || e.getCause() instanceof IndexNotFoundException) {
        return null;
    }
    if (e instanceof SearchPhaseExecutionException) {
        throw new EsClientException("unknown property was appointed.", e);
    }
    throw e;
}
 
Example #15
Source File: FessEsClient.java    From fess with Apache License 2.0 5 votes vote down vote up
public <T> T search(final String index, final SearchCondition<SearchRequestBuilder> condition,
        final SearchResult<T, SearchRequestBuilder, SearchResponse> searchResult) {
    final long startTime = System.currentTimeMillis();

    SearchResponse searchResponse = null;
    final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index);
    if (condition.build(searchRequestBuilder)) {

        final FessConfig fessConfig = ComponentUtil.getFessConfig();
        final long queryTimeout = fessConfig.getQueryTimeoutAsInteger().longValue();
        if (queryTimeout >= 0) {
            searchRequestBuilder.setTimeout(TimeValue.timeValueMillis(queryTimeout));
        }

        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Query DSL:\n{}", searchRequestBuilder);
            }
            searchResponse = searchRequestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexSearchTimeout());
        } catch (final SearchPhaseExecutionException e) {
            throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryParseError(UserMessages.GLOBAL_PROPERTY_KEY),
                    "Invalid query: " + searchRequestBuilder, e);
        }
    }
    final long execTime = System.currentTimeMillis() - startTime;

    return searchResult.build(searchRequestBuilder, execTime, OptionalEntity.ofNullable(searchResponse, () -> {}));
}
 
Example #16
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Map<String, Map<String, Object>> readMapBulk(final String indexName, final Collection<String> ids) {
    while (true) try {
        return readMapBulkInternal(indexName, ids);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient readMapBulk failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
        continue;
    }
}
 
Example #17
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read a json document from the search index for a given id.
 * Elasticsearch reads the '_source' field and parses the content as json.
 * 
 * @param id
 *            the unique identifier of a document
 * @return the document as json, matched on a Map<String, Object> object instance
 */
public Map<String, Object> readMap(final String indexName, final String id) {
    while (true) try {
        return readMapInternal(indexName, id);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient readMap failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
        continue;
    }
}
 
Example #18
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Delete documents using a query. Check what would be deleted first with a normal search query!
 * Elasticsearch once provided a native prepareDeleteByQuery method, but this was removed
 * in later versions. Instead, there is a plugin which iterates over search results,
 * see https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html
 * We simulate the same behaviour here without the need of that plugin.
 * 
 * @param q
 * @return delete document count
 */
public int deleteByQuery(String indexName, final QueryBuilder q) {
    while (true) try {
        return deleteByQueryInternal(indexName, q);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient deleteByQuery failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
        continue;
    }
}
 
Example #19
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setMapping(String indexName, String mapping) {
    try {
        this.elasticsearchClient.admin().indices().preparePutMapping(indexName)
            .setSource(mapping, XContentType.JSON)
            .setType("_default_").execute().actionGet();
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.warn("", e);
    };
}
 
Example #20
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Set<String> existBulk(String indexName, final Collection<String> ids) {
    while (true) try {
        return existBulkInternal(indexName, ids);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient existBulk failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
        continue;
    }
}
 
Example #21
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the document for a given id.
 * @param indexName the name of the index
 * @param id the unique identifier of a document
 * @return the document, if it exists or null otherwise;
 */
public boolean exist(String indexName, final String id) {
    while (true) try {
        return existInternal(indexName, id);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient exist failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
    }
}
 
Example #22
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the number of documents in the search index for a given search query
 * 
 * @param q
 *            the query
 * @return the count of all documents in the index which matches with the query
 */
public long count(final QueryBuilder q, final String indexName) {
    while (true) try {
        return countInternal(q, indexName);
    } catch (NoNodeAvailableException | IllegalStateException | ClusterBlockException | SearchPhaseExecutionException e) {
        Data.logger.info("ElasticsearchClient count failed with " + e.getMessage() + ", retrying to connect node...");
        try {Thread.sleep(1000);} catch (InterruptedException ee) {}
        connect();
    }
}
 
Example #23
Source File: ElasticsearchExecutionExceptionMapper.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public Response toResponse( SearchPhaseExecutionException spee ){
    return toResponse( SERVICE_UNAVAILABLE, spee );

}
 
Example #24
Source File: EsTypeImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof SearchPhaseExecutionException;
}
 
Example #25
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
public <T> long scrollSearch(final String index, final SearchCondition<SearchRequestBuilder> condition,
        final EntityCreator<T, SearchResponse, SearchHit> creator, final BooleanFunction<T> cursor) {
    long count = 0;

    final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index).setScroll(scrollForSearch);
    if (condition.build(searchRequestBuilder)) {
        final FessConfig fessConfig = ComponentUtil.getFessConfig();

        String scrollId = null;
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Query DSL:\n{}", searchRequestBuilder);
            }
            SearchResponse response = searchRequestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexSearchTimeout());

            scrollId = response.getScrollId();
            while (scrollId != null) {
                final SearchHits searchHits = response.getHits();
                final SearchHit[] hits = searchHits.getHits();
                if (hits.length == 0) {
                    break;
                }

                for (final SearchHit hit : hits) {
                    count++;
                    if (!cursor.apply(creator.build(response, hit))) {
                        if (scrollId != null) {
                            client.prepareClearScroll().addScrollId(scrollId)
                                    .execute(ActionListener.wrap(res -> {}, e1 -> logger.warn("Failed to clear scrollId.", e1)));
                        }
                        break;
                    }
                }

                response =
                        client.prepareSearchScroll(scrollId).setScroll(scrollForDelete).execute()
                                .actionGet(fessConfig.getIndexBulkTimeout());
                scrollId = response.getScrollId();
            }
        } catch (final SearchPhaseExecutionException e) {
            if (scrollId != null) {
                client.prepareClearScroll().addScrollId(scrollId)
                        .execute(ActionListener.wrap(res -> {}, e1 -> logger.warn("Failed to clear scrollId.", e1)));
            }
            throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryParseError(UserMessages.GLOBAL_PROPERTY_KEY),
                    "Invalid query: " + searchRequestBuilder, e);
        }
    }

    return count;
}
 
Example #26
Source File: EsTypeImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof IndexMissingException
            || e.getCause() instanceof IndexMissingException
            || e instanceof SearchPhaseExecutionException;
}
 
Example #27
Source File: EsIndexImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof SearchPhaseExecutionException;
}
 
Example #28
Source File: EsIndexImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof IndexMissingException
            || e.getCause() instanceof IndexMissingException
            || e instanceof SearchPhaseExecutionException;
}
 
Example #29
Source File: EsIndexImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof IndexMissingException
            || e.getCause() instanceof IndexMissingException
            || e instanceof SearchPhaseExecutionException;
}
 
Example #30
Source File: EsTypeImpl.java    From io with Apache License 2.0 4 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof SearchPhaseExecutionException;
}