Search in sources :

Example 61 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.

the class EsDaoSearchTest method assertDocumentExisit.

private void assertDocumentExisit(String indexName, String typeName, String id, boolean expected) {
    GetResponse response = getDocument(indexName, typeName, id);
    assertEquals(expected, response.isExists());
    assertEquals(expected, !response.isSourceEmpty());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse)

Example 62 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.

the class EsDaoSuggestionTest method assertDocumentExisit.

private void assertDocumentExisit(String indexName, String typeName, String id, boolean expected) {
    GetResponse response = getDocument(indexName, typeName, id);
    assertEquals(expected, response.isExists());
    assertEquals(expected, !response.isSourceEmpty());
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse)

Example 63 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project fess-crawler by codelibs.

the class AbstractCrawlerService method get.

protected <T> T get(final Class<T> clazz, final String sessionId, final String url) {
    final String id = getId(sessionId, url);
    final GetResponse response = getClient().get(c -> c.prepareGet(index, type, id).execute());
    if (response.isExists()) {
        final Map<String, Object> source = response.getSource();
        final T bean = BeanUtil.copyMapToNewBean(source, clazz, option -> {
            option.converter(new EsTimestampConverter(), timestampFields).excludeWhitespace();
            option.exclude(EsAccessResult.ACCESS_RESULT_DATA);
        });
        @SuppressWarnings("unchecked") final Map<String, Object> data = (Map<String, Object>) source.get(EsAccessResult.ACCESS_RESULT_DATA);
        if (data != null) {
            ((EsAccessResult) bean).setAccessResultData(new EsAccessResultData(data));
        }
        setId(bean, id);
        return bean;
    }
    return null;
}
Also used : EsAccessResultData(org.codelibs.fess.crawler.entity.EsAccessResultData) EsAccessResult(org.codelibs.fess.crawler.entity.EsAccessResult) GetResponse(org.elasticsearch.action.get.GetResponse) Map(java.util.Map) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Example 64 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project elasticsearch-river-couchdb by elastic.

the class CouchdbRiverIntegrationTest method testCreateCouchdbDatabaseWhileRunning_17.

/**
 * Test case for #17: https://github.com/elasticsearch/elasticsearch-river-couchdb/issues/17
 */
@Test
public void testCreateCouchdbDatabaseWhileRunning_17() throws IOException, InterruptedException {
    final int nbDocs = between(50, 300);
    logger.info("  -> Checking couchdb running");
    CouchDBClient.checkCouchDbRunning();
    logger.info("  -> Create index");
    try {
        createIndex(getDbName());
    } catch (IndexAlreadyExistsException e) {
    // No worries. We already created the index before
    }
    logger.info("  -> Create river");
    index("_river", getDbName(), "_meta", jsonBuilder().startObject().field("type", "couchdb").endObject());
    // Check that the river is started
    assertThat(awaitBusy(new Predicate<Object>() {

        public boolean apply(Object obj) {
            try {
                refresh();
                GetResponse response = get("_river", getDbName(), "_status");
                return response.isExists();
            } catch (IndexMissingException e) {
                return false;
            }
        }
    }, 5, TimeUnit.SECONDS), equalTo(true));
    logger.info("  -> Creating test database [{}]", getDbName());
    CouchDBClient.dropAndCreateTestDatabase(getDbName());
    logger.info("  -> Inserting [{}] docs in couchdb", nbDocs);
    for (int i = 0; i < nbDocs; i++) {
        CouchDBClient.putDocument(getDbName(), "" + i, "foo", "bar", "content", "" + i);
    }
    // Check that docs are still processed by the river
    assertThat(awaitBusy(new Predicate<Object>() {

        public boolean apply(Object obj) {
            try {
                refresh();
                SearchResponse response = client().prepareSearch(getDbName()).get();
                logger.info("  -> got {} docs in {} index", response.getHits().totalHits(), getDbName());
                return response.getHits().totalHits() == nbDocs;
            } catch (IndexMissingException e) {
                return false;
            }
        }
    }, 1, TimeUnit.MINUTES), equalTo(true));
}
Also used : IndexAlreadyExistsException(org.elasticsearch.indices.IndexAlreadyExistsException) IndexMissingException(org.elasticsearch.indices.IndexMissingException) GetResponse(org.elasticsearch.action.get.GetResponse) Predicate(org.elasticsearch.common.base.Predicate) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test) ElasticsearchIntegrationTest(org.elasticsearch.test.ElasticsearchIntegrationTest)

Example 65 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project flink by apache.

the class TestClientBase method assertThatIdsAreNotWritten.

void assertThatIdsAreNotWritten(String index, int... ids) throws IOException {
    for (final int id : ids) {
        try {
            final GetResponse response = getResponse(index, id);
            assertFalse(response.isExists(), String.format("Id %s is unexpectedly present.", id));
        } catch (ElasticsearchStatusException e) {
            assertEquals(404, e.status().getStatus());
        }
    }
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)167 Test (org.junit.Test)50 GetRequest (org.elasticsearch.action.get.GetRequest)28 Map (java.util.Map)27 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)26 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 Date (java.util.Date)18 ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)17 Dml (com.alibaba.otter.canal.client.adapter.support.Dml)17 LinkedHashMap (java.util.LinkedHashMap)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)14 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)14 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 Settings (org.elasticsearch.common.settings.Settings)10 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 IndexResponse (org.elasticsearch.action.index.IndexResponse)7