org.elasticsearch.indices.IndexMissingException Java Examples

The following examples show how to use org.elasticsearch.indices.IndexMissingException. 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メソッドで初回にIndexMissingExceptionが投げられた場合のテスト.
 */
@Test
public void EsIndex_searchメソッドで初回にIndexMissingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsIndexImpl esIndexObject = Mockito.spy(new EsIndexImpl("dummy", "", 0, 0, null));

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

    // EsType#asyncGet()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    IndexMissingException toBeThrown = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncGet(Mockito.anyString(), Mockito.anyBoolean());
    // メソッド呼び出し
    DcGetResponse result = esTypeObject.get("dummyId", true);
    assertNull(result);
}
 
Example #3
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncGet()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncGet(Mockito.anyString(), Mockito.anyBoolean());
    // メソッド呼び出し
    DcGetResponse result = esTypeObject.get("dummyId", true);
    assertNull(result);
}
 
Example #4
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にIndexMissingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にIndexMissingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    IndexMissingException toBeThrown = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    (OpType) Mockito.anyObject(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.update("dummyId", null, 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof IndexMissingException);
    }
}
 
Example #5
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

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

    // EsType#asyncSearch()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    IndexMissingException toBeThrown = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esTypeObject.search(null);
    assertTrue(result.isNullResponse());
}
 
Example #7
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esTypeObject.search(null);
    assertTrue(result.isNullResponse());
}
 
Example #8
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_deleteメソッドで初回にIndexMissingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_deleteメソッドで初回にIndexMissingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncDelete()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    IndexMissingException toBeThrown = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncDelete(Mockito.anyString(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.delete("dummyId", 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof IndexMissingException);
    }
}
 
Example #9
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncDelete()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncDelete(Mockito.anyString(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.delete("dummyId", 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexMissingException);
    }
}
 
Example #10
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_putMappingメソッドで初回にIndexMissingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_putMappingメソッドで初回にIndexMissingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

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

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

    // EsIndex#asyncIndexSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esIndexObject)
            .asyncIndexSearch(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esIndexObject.search("dummyRoutingId", (Map<String, Object>) null);
    assertNull(result);
}
 
Example #13
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストでリトライ対象外の例外が発生した場合、リトライせずに初回例外を投げること.
 */
@Test(expected = EsClientException.class)
public void 初回リクエストでリトライ対象外の例外が発生した場合_リトライせずに初回例外を投げること() {
    TestRequest requestMock = Mockito.spy(new TestRequest());

    Mockito.doThrow(new IndexMissingException(new Index("abc"))) // なぜかモック例外だとうまく動かなかった.
            .when(requestMock)
            .doProcess();

    try {
        requestMock.doRequest();
        fail("Should not return");
    } finally {
        Mockito.verify(requestMock, Mockito.times(1)).doProcess();
        Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
    }
}
 
Example #14
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合、EsClientExceptionが投げられること.
 */
@Test(expected = EsClientException.class)
public void リトライ対象例外が続き_リトライ5回目でリトライ対象外の例外が発生した場合_EsClientExceptionが投げられること() {

    TestRequest requestMock = Mockito.spy(new TestRequest());

    ClusterBlockException toBeThrown = Mockito.mock(ClusterBlockException.class);
    IndexMissingException toBeThrown2 = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown) // 初回
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(toBeThrown) // リトライ2回目
            .doThrow(toBeThrown) // リトライ3回目
            .doThrow(toBeThrown) // リトライ4回目
            .doThrow(toBeThrown2) // リトライ5回目
            .when(requestMock)
            .doProcess();

    try {
        requestMock.doRequest();
        fail("Should not return");
    } finally {
        // doProcessが6回呼び出されるはず
        Mockito.verify(requestMock, Mockito.times(6)).doProcess();
        Mockito.verify(requestMock, Mockito.times(0)).onParticularError(Mockito.any(ElasticsearchException.class));
    }
}
 
Example #15
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回でIndexMissingExceptionが発生した場合にEsClient_EsIndexMissingExceptionが返されること.
 */
@Test(expected = EsClientException.EsIndexMissingException.class)
public void ドキュメント新規作成時_初回でIndexMissingExceptionが発生した場合にEsClient_EsIndexMissingExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    IndexMissingException toBeThrown = Mockito.mock(IndexMissingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", null);
    fail("EsIndexMissingException should be thrown.");
}
 
Example #16
Source File: EsEntityIndexImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private long getIndexSize(){
    long indexSize = 0L;
    final String indexName = indexLocationStrategy.getIndexInitialName();
    try {
        final IndicesStatsResponse statsResponse = esProvider.getClient()
            .admin()
            .indices()
            .prepareStats(indexName)
            .all()
            .execute()
            .actionGet();
        final CommonStats indexStats = statsResponse.getIndex(indexName).getTotal();
        indexSize = indexStats.getStore().getSizeInBytes();
    } catch (IndexMissingException e) {
        // if for some reason the index size does not exist,
        // log an error and we can assume size is 0 as it doesn't exist
        logger.error("Unable to get size for index {} due to IndexMissingException for app {}",
            indexName, indexLocationStrategy.getApplicationScope().getApplication().getUuid());
    }
    return indexSize;
}
 
Example #17
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
PutMappingResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        throw new EsClientException.EsIndexMissingException(e);
    }
    if (e instanceof MapperParsingException) {
        throw new EsClientException.EsSchemaMismatchException(e);
    }
    throw e;
}
 
Example #18
Source File: EsRetry2Test.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * ドキュメント新規作成時_初回で根本例外IndexMissingExceptionが発生した場合にEsClient_EsIndexMissingExceptionが返されること.
 */
@Test(expected = EsClientException.EsIndexMissingException.class)
public void ドキュメント新規作成時_初回で根本例外IndexMissingExceptionが発生した場合にEsClient_EsIndexMissingExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));
    // EsType#asyncIndex()が呼ばれた場合に、根本例外にIndexMissingExceptionを含むElasticsearchExceptionを投げる。
    ElasticsearchException toBeThrown = new ElasticsearchException("dummy", new IndexMissingException(new Index(
            "foo")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    esTypeObject.create("dummyId", null);
    fail("EsIndexMissingException should be thrown.");
}
 
Example #19
Source File: AbstractNodeTest.java    From elasticsearch-gatherer with Apache License 2.0 5 votes vote down vote up
@AfterMethod
public void deleteIndices() {
    logger.info("deleting index {}", INDEX);
    try {
        client("1").admin().indices().delete(new DeleteIndexRequest().indices(INDEX)).actionGet();
    } catch (IndexMissingException e) {
        // ignore
    }
    logger.info("index {} deleted", INDEX);
    closeAllNodes();
}
 
Example #20
Source File: Importer.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
private Set<String> getMissingIndexes(Set<String> indexes) {
    try {
        ImmutableMap<String, IndexMetaData> foundIndices = getIndexMetaData(indexes);
        indexes.removeAll(foundIndices.keySet());
    } catch (IndexMissingException e) {
        // all indexes are missing
    }
    return indexes;
}
 
Example #21
Source File: RestExportActionTest.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
private boolean deleteIndex(String name) {
    try {
        esSetup.client().admin().indices().prepareDelete(name).execute().actionGet();
    } catch (IndexMissingException e) {
        return false;
    }
    return true;
}
 
Example #22
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
GetResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        return null;
    }
    throw e;
}
 
Example #23
Source File: AnalyticsServiceElasticsearch.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
private static boolean refresh(String index) {
    try {
        AdminClient adminClient = client.getClient().admin();
        RefreshRequestBuilder refreshRequestBuilder = adminClient.indices().prepareRefresh(index);
        adminClient.indices().refresh(refreshRequestBuilder.request()).actionGet();
        return true;
    } catch (IndexMissingException t) {
        // Ignore, as means that no traces have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("Index [%s] not found, unable to proceed.", index);
        }
        return false;
    }
}
 
Example #24
Source File: EsClient.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * クエリを指定してスクロールサーチを実行する.
 * @param index インデックス名
 * @param type タイプ名
 * @param query 検索クエリ
 * @return 検索結果
 */
public DcSearchResponse scrollSearch(String index, String type, Map<String, Object> query) {
    try {
        return DcSearchResponseImpl.getInstance(internalClient.asyncScrollSearch(index, type, query).actionGet());
    } catch (IndexMissingException e) {
        throw new EsClientException.EsIndexMissingException(e);
    }
}
 
Example #25
Source File: EsIndexImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
DeleteIndexResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        throw new EsClientException.EsIndexMissingException(e);
    }
    throw e;
}
 
Example #26
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 #27
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 #28
Source File: AnalyzeHelper.java    From es-service-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 分词-无法分词则返回空集合
 * 
 * @param analyzer
 * @param str
 * @return
 */
public static List<String> analyze(String analyzer, String str) {

    AnalyzeResponse ar = null;
    try {
        AnalyzeRequest request = new AnalyzeRequest(str).analyzer(analyzer).index(
                getCurrentValidIndex());
        ar = ESClient.getClient().admin().indices().analyze(request).actionGet();
    } catch (IndexMissingException e) {
        if (!reLoad) {
            synchronized (AnalyzeHelper.class) {
                if (!reLoad) {
                    reLoad = true;
                }
            }
        }
        return analyze(analyzer, str);
    }

    if (ar == null || ar.getTokens() == null || ar.getTokens().size() < 1) {
        return Lists.newArrayList();
    }
    List<String> analyzeTokens = Lists.newArrayList();
    for (AnalyzeToken at : ar.getTokens()) {
        analyzeTokens.add(at.getTerm());
    }
    return analyzeTokens;
}
 
Example #29
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
boolean isParticularError(ElasticsearchException e) {
    return e instanceof DocumentAlreadyExistsException
            || e instanceof IndexMissingException
            || e.getCause() instanceof IndexMissingException
            || e instanceof MapperParsingException;
}
 
Example #30
Source File: EsTypeImpl.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
IndexResponse onParticularError(ElasticsearchException e) {
    if (e instanceof IndexMissingException || e.getCause() instanceof IndexMissingException) {
        throw new EsClientException.EsIndexMissingException(e);
    }
    if (e instanceof MapperParsingException) {
        throw new EsClientException.EsSchemaMismatchException(e);
    }
    // 既知のExceptionの場合はINFOログ
    // 新規のExceptionの場合はWARNログ
    if (e instanceof DocumentAlreadyExistsException) {
        if (e.getClass() != null) {
            log.info(e.getClass().getName() + " : " + e.getMessage());
        } else {
            log.info(e.getMessage());
        }
    } else {
        if (e.getClass() != null) {
            log.warn(e.getClass().getName() + " : " + e.getMessage());
        } else {
            log.warn(e.getMessage());
        }
    }
    // 例外が発生した場合でもドキュメントが登録されている可能性がある。
    // そのため、登録チェックを行い、データが登録済の場合は正常なレスポンスを返却する。
    return checkDocumentCreated(id, data, e);
}