Package org.elasticsearch.action.get

Examples of org.elasticsearch.action.get.GetResponse


                .endArray()
                .endObject()).execute().actionGet();

        // flush, so we fetch it from the index (as see that we filter nested docs)
        client.admin().indices().prepareFlush().setRefresh(true).execute().actionGet();
        GetResponse getResponse = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(getResponse.exists(), equalTo(true));

        // check the numDocs
        IndicesStatusResponse statusResponse = client.admin().indices().prepareStatus().execute().actionGet();
        assertThat(statusResponse.index("test").docs().numDocs(), equalTo(3));
View Full Code Here


                .endArray()
                .endObject()).execute().actionGet();

        // flush, so we fetch it from the index (as see that we filter nested docs)
        client.admin().indices().prepareFlush().setRefresh(true).execute().actionGet();
        GetResponse getResponse = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(getResponse.exists(), equalTo(true));

        // check the numDocs
        IndicesStatusResponse statusResponse = client.admin().indices().prepareStatus().execute().actionGet();
        assertThat(statusResponse.index("test").docs().numDocs(), equalTo(7));
View Full Code Here

        // verify that mapping is there
        clusterState = client("server1").admin().cluster().state(clusterStateRequest()).actionGet();
        assertThat(clusterState.state().metaData().index("test").mapping("type1"), notNullValue());

        logger.info("Getting #1, should not exists");
        GetResponse getResponse = client("server1").get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResponse.exists(), equalTo(false));
        logger.info("Getting #2");
        getResponse = client("server1").get(getRequest("test").type("type1").id("2")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("2", "test")));

        // Now flush and add some data (so we have index recovery as well)
        logger.info("Flushing, so we have actual content in the index files (#2 should be in the index)");
        client("server1").admin().indices().flush(flushRequest("test")).actionGet();
        logger.info("Indexing #3, so we have something in the translog as well");
        client("server1").index(Requests.indexRequest("test").type("type1").id("3").source(source("3", "test"))).actionGet();

        logger.info("Gateway Snapshot");
        client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();
        logger.info("Gateway Snapshot (should be a no op)");
        client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();

        logger.info("Closing the server");
        closeNode("server1");
        logger.info("Starting the server, should recover from the gateway (both index and translog) and reuse work dir");
        startNode("server1");

        logger.info("Running Cluster Health (wait for the shards to startup)");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

        logger.info("Getting #1, should not exists");
        getResponse = client("server1").get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResponse.exists(), equalTo(false));
        logger.info("Getting #2 (not from the translog, but from the index)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("2")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("2", "test")));
        logger.info("Getting #3 (from the translog)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("3")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("3", "test")));

        logger.info("Closing the server");
        closeNode("server1");
        logger.info("Clearing cluster data dir, so there will be a full recovery from the gateway");
        FileSystemUtils.deleteRecursively(environment.dataWithClusterFile());
        logger.info("Starting the server, should recover from the gateway (both index and translog) without reusing work dir");
        startNode("server1");

        logger.info("Running Cluster Health (wait for the shards to startup)");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

        logger.info("Getting #1, should not exists");
        getResponse = client("server1").get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResponse.exists(), equalTo(false));
        logger.info("Getting #2 (not from the translog, but from the index)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("2")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("2", "test")));
        logger.info("Getting #3 (from the translog)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("3")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("3", "test")));


        logger.info("Flushing, so we have actual content in the index files (#3 should be in the index now as well)");
        client("server1").admin().indices().flush(flushRequest("test")).actionGet();

        logger.info("Gateway Snapshot");
        client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();
        logger.info("Gateway Snapshot (should be a no op)");
        client("server1").admin().indices().gatewaySnapshot(gatewaySnapshotRequest("test")).actionGet();

        logger.info("Closing the server");
        closeNode("server1");
        logger.info("Starting the server, should recover from the gateway (just from the index, nothing in the translog)");
        startNode("server1");

        logger.info("Running Cluster Health (wait for the shards to startup)");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));

        logger.info("Getting #1, should not exists");
        getResponse = client("server1").get(getRequest("test").type("type1").id("1")).actionGet();
        assertThat(getResponse.exists(), equalTo(false));
        logger.info("Getting #2 (not from the translog, but from the index)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("2")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("2", "test")));
        logger.info("Getting #3 (not from the translog, but from the index)");
        getResponse = client("server1").get(getRequest("test").type("type1").id("3")).actionGet();
        assertThat(getResponse.sourceAsString(), equalTo(source("3", "test")));

        logger.info("Deleting the index");
        client("server1").admin().indices().delete(deleteIndexRequest("test")).actionGet();
    }
View Full Code Here

        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

        GetResponse getResult;

        for (int i = 0; i < 5; i++) {
            getResult = client("server1").get(getRequest("test").type("type1").id("1").operationThreaded(false)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("1", "test")));
            getResult = client("server2").get(getRequest("test").type("type1").id("1").operationThreaded(false)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("1", "test")));
            getResult = client("server1").get(getRequest("test").type("type1").id("2").operationThreaded(true)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("2", "test")));
            getResult = client("server2").get(getRequest("test").type("type1").id("2").operationThreaded(true)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("2", "test")));
        }

        // now start another one so we move some primaries
        startNode("server3", recoverySettings());
        Thread.sleep(200);
        logger.info("Running Cluster Health");
        clusterHealth = client("server1").admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForRelocatingShards(0).waitForNodes("3")).actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

        for (int i = 0; i < 5; i++) {
            getResult = client("server1").get(getRequest("test").type("type1").id("1")).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("1", "test")));
            getResult = client("server2").get(getRequest("test").type("type1").id("1")).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("1", "test")));
            getResult = client("server3").get(getRequest("test").type("type1").id("1")).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("1", "test")));
            getResult = client("server1").get(getRequest("test").type("type1").id("2").operationThreaded(true)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("2", "test")));
            getResult = client("server2").get(getRequest("test").type("type1").id("2").operationThreaded(true)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("2", "test")));
            getResult = client("server3").get(getRequest("test").type("type1").id("2").operationThreaded(true)).actionGet(1000);
            assertThat(getResult.sourceAsString(), equalTo(source("2", "test")));
        }
    }
View Full Code Here

        logger.info("Optimizing");
        OptimizeResponse optimizeResponse = client1.admin().indices().prepareOptimize("test").execute().actionGet();
        assertThat(optimizeResponse.successfulShards(), equalTo(10));
        assertThat(optimizeResponse.failedShards(), equalTo(0));

        GetResponse getResult;

        logger.info("Get [type1/1]");
        for (int i = 0; i < 5; i++) {
            getResult = client1.prepareGet("test", "type1", "1").setOperationThreaded(false).execute().actionGet();
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("1", "test").string()));
            assertThat("cycle(map) #" + i, (String) ((Map) getResult.sourceAsMap().get("type1")).get("name"), equalTo("test"));
            getResult = client1.get(getRequest("test").type("type1").id("1").operationThreaded(true)).actionGet();
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("1", "test").string()));
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
        }

        logger.info("Get [type1/1] with script");
        for (int i = 0; i < 5; i++) {
            getResult = client1.prepareGet("test", "type1", "1").setFields("_source.type1.name").execute().actionGet();
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
            assertThat(getResult.exists(), equalTo(true));
            assertThat(getResult.source(), nullValue());
            assertThat(getResult.field("_source.type1.name").values().get(0).toString(), equalTo("test"));
        }

        logger.info("Get [type1/2] (should be empty)");
        for (int i = 0; i < 5; i++) {
            getResult = client1.get(getRequest("test").type("type1").id("2")).actionGet();
            assertThat(getResult.exists(), equalTo(false));
        }

        logger.info("Delete [type1/1]");
        DeleteResponse deleteResponse = client1.prepareDelete("test", "type1", "1").setReplicationType(ReplicationType.SYNC).execute().actionGet();
        assertThat(deleteResponse.index(), equalTo(getConcreteIndexName()));
        assertThat(deleteResponse.id(), equalTo("1"));
        assertThat(deleteResponse.type(), equalTo("type1"));
        logger.info("Refreshing");
        client1.admin().indices().refresh(refreshRequest("test")).actionGet();

        logger.info("Get [type1/1] (should be empty)");
        for (int i = 0; i < 5; i++) {
            getResult = client1.get(getRequest("test").type("type1").id("1")).actionGet();
            assertThat(getResult.exists(), equalTo(false));
        }

        logger.info("Index [type1/1]");
        client1.index(indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();
        logger.info("Index [type1/2]");
        client1.index(indexRequest("test").type("type1").id("2").source(source("2", "test2"))).actionGet();

        logger.info("Flushing");
        FlushResponse flushResult = client1.admin().indices().prepareFlush("test").execute().actionGet();
        assertThat(flushResult.successfulShards(), equalTo(10));
        assertThat(flushResult.failedShards(), equalTo(0));
        logger.info("Refreshing");
        client1.admin().indices().refresh(refreshRequest("test")).actionGet();

        logger.info("Get [type1/1] and [type1/2]");
        for (int i = 0; i < 5; i++) {
            getResult = client1.get(getRequest("test").type("type1").id("1")).actionGet();
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("1", "test").string()));
            getResult = client1.get(getRequest("test").type("type1").id("2")).actionGet();
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("2", "test2").string()));
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
        }

        logger.info("Count");
        // check count
        for (int i = 0; i < 5; i++) {
            // test successful
            CountResponse countResponse = client1.prepareCount("test").setQuery(termQuery("_type", "type1")).setOperationThreading(BroadcastOperationThreading.NO_THREADS).execute().actionGet();
            assertThat("Failures " + countResponse.shardFailures(), countResponse.shardFailures().size(), equalTo(0));
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));

            countResponse = client1.count(countRequest("test").query(termQuery("_type", "type1")).operationThreading(BroadcastOperationThreading.SINGLE_THREAD)).actionGet();
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));

            countResponse = client1.count(countRequest("test").query(termQuery("_type", "type1")).operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD)).actionGet();
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));

            // test failed (simply query that can't be parsed)
            countResponse = client1.count(countRequest("test").query(Unicode.fromStringAsBytes("{ term : { _type : \"type1 } }"))).actionGet();

            assertThat(countResponse.count(), equalTo(0l));
            assertThat(countResponse.successfulShards(), equalTo(0));
            assertThat(countResponse.failedShards(), equalTo(5));
        }

        logger.info("Delete by query");
        DeleteByQueryResponse queryResponse = client2.prepareDeleteByQuery().setIndices("test").setQuery(termQuery("name", "test2")).execute().actionGet();
        assertThat(queryResponse.index(getConcreteIndexName()).successfulShards(), equalTo(5));
        assertThat(queryResponse.index(getConcreteIndexName()).failedShards(), equalTo(0));
        client1.admin().indices().refresh(refreshRequest("test")).actionGet();

        logger.info("Get [type1/1] and [type1/2], should be empty");
        for (int i = 0; i < 5; i++) {
            getResult = client1.get(getRequest("test").type("type1").id("1")).actionGet();
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("1", "test").string()));
            getResult = client1.get(getRequest("test").type("type1").id("2")).actionGet();
            assertThat("cycle #" + i, getResult.exists(), equalTo(false));
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
        }
    }
View Full Code Here

        assertThat(refreshResponse.successfulShards(), equalTo(10));
        assertThat(refreshResponse.failedShards(), equalTo(0));


        for (int i = 0; i < 5; i++) {
            GetResponse getResult = client1.get(getRequest("test").type("type1").id("1")).actionGet();
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
            assertThat("cycle #" + i, getResult.exists(), equalTo(false));

            getResult = client1.get(getRequest("test").type("type1").id("2")).actionGet();
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("2", "test").string()));
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));

            getResult = client1.get(getRequest("test").type("type1").id(generatedId3)).actionGet();
            assertThat("cycle #" + i, getResult.sourceAsString(), equalTo(source("3", "test").string()));
            assertThat(getResult.index(), equalTo(getConcreteIndexName()));
        }
    }
View Full Code Here

        ClusterHealthResponse clusterHealth = client.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));

        GetResponse response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(false));

        logger.info("--> index doc 1");
        client.prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2").execute().actionGet();

        logger.info("--> realtime get 1");
        response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2"));

        logger.info("--> realtime get 1 (no source)");
        response = client.prepareGet("test", "type1", "1").setFields(Strings.EMPTY_ARRAY).execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.source(), nullValue());

        logger.info("--> realtime get 1 (no type)");
        response = client.prepareGet("test", null, "1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2"));

        logger.info("--> non realtime get 1");
        response = client.prepareGet("test", "type1", "1").setRealtime(false).execute().actionGet();
        assertThat(response.exists(), equalTo(false));

        logger.info("--> realtime fetch of field (requires fetching parsing source)");
        response = client.prepareGet("test", "type1", "1").setFields("field1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.source(), nullValue());
        assertThat(response.field("field1").values().get(0).toString(), equalTo("value1"));
        assertThat(response.field("field2"), nullValue());

        logger.info("--> flush the index, so we load it from it");
        client.admin().indices().prepareFlush().execute().actionGet();

        logger.info("--> realtime get 1 (loaded from index)");
        response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2"));

        logger.info("--> non realtime get 1 (loaded from index)");
        response = client.prepareGet("test", "type1", "1").setRealtime(false).execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2"));

        logger.info("--> realtime fetch of field (loaded from index)");
        response = client.prepareGet("test", "type1", "1").setFields("field1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.source(), nullValue());
        assertThat(response.field("field1").values().get(0).toString(), equalTo("value1"));
        assertThat(response.field("field2"), nullValue());

        logger.info("--> update doc 1");
        client.prepareIndex("test", "type1", "1").setSource("field1", "value1_1", "field2", "value2_1").execute().actionGet();

        logger.info("--> realtime get 1");
        response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1_1"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2_1"));

        logger.info("--> update doc 1 again");
        client.prepareIndex("test", "type1", "1").setSource("field1", "value1_2", "field2", "value2_2").execute().actionGet();

        response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(true));
        assertThat(response.sourceAsMap().get("field1").toString(), equalTo("value1_2"));
        assertThat(response.sourceAsMap().get("field2").toString(), equalTo("value2_2"));

        DeleteResponse deleteResponse = client.prepareDelete("test", "type1", "1").execute().actionGet();
        assertThat(deleteResponse.notFound(), equalTo(false));

        response = client.prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(response.exists(), equalTo(false));
    }
View Full Code Here

        client.prepareIndex("test", "type1", Integer.toString(10000)).setSource(buildSource(10000)).execute().actionGet();

        client.admin().indices().prepareRefresh().execute().actionGet();

        for (int i = 1; i < 100; i++) {
            GetResponse getResponse = client.prepareGet("test", "type1", Integer.toString(i)).execute().actionGet();
            assertThat(getResponse.source(), equalTo(buildSource(i).copiedBytes()));
        }
        GetResponse getResponse = client.prepareGet("test", "type1", Integer.toString(10000)).execute().actionGet();
        assertThat(getResponse.source(), equalTo(buildSource(10000).copiedBytes()));

        for (int i = 1; i < 100; i++) {
            SearchResponse searchResponse = client.prepareSearch().setQuery(QueryBuilders.idsQuery("type1").ids(Integer.toString(i))).execute().actionGet();
            assertThat(searchResponse.hits().getTotalHits(), equalTo(1l));
            assertThat(searchResponse.hits().getAt(0).source(), equalTo(buildSource(i).copiedBytes()));
View Full Code Here

        assertThat(stateResponse.state().metaData().index("test").state(), equalTo(IndexMetaData.State.OPEN));
        assertThat(stateResponse.state().routingTable().index("test").shards().size(), equalTo(2));
        assertThat(stateResponse.state().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));

        logger.info("--> trying to get the indexed document on the first index");
        GetResponse getResponse = client("node1").prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(getResponse.exists(), equalTo(true));

        logger.info("--> closing test index...");
        client("node1").admin().indices().prepareClose("test").execute().actionGet();
        stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
        assertThat(stateResponse.state().metaData().index("test").state(), equalTo(IndexMetaData.State.CLOSE));
        assertThat(stateResponse.state().routingTable().index("test"), nullValue());

        logger.info("--> closing nodes...");
        closeNode("node2");
        closeNode("node1");

        logger.info("--> starting nodes again...");
        startNode("node1", settingsBuilder().put("gateway.type", "local").build());
        startNode("node2", settingsBuilder().put("gateway.type", "local").build());

        logger.info("--> waiting for two nodes and green status");
        health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
        assertThat(health.timedOut(), equalTo(false));

        stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
        assertThat(stateResponse.state().metaData().index("test").state(), equalTo(IndexMetaData.State.CLOSE));
        assertThat(stateResponse.state().routingTable().index("test"), nullValue());

        logger.info("--> trying to index into a closed index ...");
        try {
            client("node1").prepareIndex("test", "type1", "1").setSource("field1", "value1").setTimeout("1s").execute().actionGet();
            assert false;
        } catch (ClusterBlockException e) {
            // all is well
        }

        logger.info("--> opening index...");
        client("node1").admin().indices().prepareOpen("test").execute().actionGet();

        logger.info("--> waiting for green status");
        health = client("node1").admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
        assertThat(health.timedOut(), equalTo(false));

        stateResponse = client("node1").admin().cluster().prepareState().execute().actionGet();
        assertThat(stateResponse.state().metaData().index("test").state(), equalTo(IndexMetaData.State.OPEN));
        assertThat(stateResponse.state().routingTable().index("test").shards().size(), equalTo(2));
        assertThat(stateResponse.state().routingTable().index("test").shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));

        logger.info("--> trying to get the indexed document on the first round (before close and shutdown)");
        getResponse = client("node1").prepareGet("test", "type1", "1").execute().actionGet();
        assertThat(getResponse.exists(), equalTo(true));

        logger.info("--> indexing a simple document");
        client("node1").prepareIndex("test", "type1", "2").setSource("field1", "value1").execute().actionGet();
    }
View Full Code Here

        }
        String fieldValue = sb.toString();
        client.prepareIndex("test", "type", "1").setSource("field", fieldValue).execute().actionGet();

        // realtime get
        GetResponse getResponse = client.prepareGet("test", "type", "1").execute().actionGet();
        assertThat(getResponse.exists(), equalTo(true));
        assertThat(getResponse.sourceAsMap().get("field").toString(), equalTo(fieldValue));
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.get.GetResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.