Package org.elasticsearch.action.count

Examples of org.elasticsearch.action.count.CountResponse


        startEsNode();

        final Client client = node.client();
        final SearchRequestBuilder srb = client.prepareSearch();

        final CountResponse countResponse = client.prepareCount(commandLineOptions.getIndicesArray()).execute().actionGet();
        final long totalCount = countResponse.getCount();

        long changedCount = 0;
        long processedCount = 0;

        srb.setIndices(commandLineOptions.getIndicesArray());
View Full Code Here


        // Check that docs are indexed by the river
        assertThat(awaitBusy(new Predicate<Object>() {
            public boolean apply(Object obj) {
                try {
                    refresh();
                    CountResponse response = client().prepareCount("wikipedia").get();
                    logger.info("  -> got {} docs in {} index", response.getCount());
                    return response.getCount() > 0;
                } catch (IndexMissingException e) {
                    return false;
                }
            }
        }, 1, TimeUnit.MINUTES), equalTo(true));
View Full Code Here

        // Check that docs are indexed by the river
        assertThat(awaitBusy(new Predicate<Object>() {
            public boolean apply(Object obj) {
                try {
                    refresh();
                    CountResponse response = client().prepareCount("wikipedia").get();
                    logger.info("  -> got {} docs in {} index", response.getCount());
                    return response.getCount() > 0;
                } catch (IndexMissingException e) {
                    return false;
                }
            }
        }, 1, TimeUnit.MINUTES), equalTo(true));
View Full Code Here

            }
        }

        // check the count
        for (int i = 0; i < (nodes.length * 5); i++) {
            CountResponse count = client.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            logger.info("indexed [{}], count [{}], [{}]", count.count(), indexCounter.get(), count.count() == indexCounter.get() ? "OK" : "FAIL");
            if (count.count() != indexCounter.get()) {
                logger.warn("count does not match!");
            }
        }

        // scan all the docs, verify all have the same version based on the number of replicas
View Full Code Here

        }

        System.out.println("Verifying counts...");
        for (int index = 0; index < NUM_INDICES; index++) {
            String indexName = "index_" + index;
            CountResponse count = client.prepareCount(indexName).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
            if (count.count() != NUM_DOCS) {
                System.err.println("Wrong count value, expected [" + NUM_DOCS + "], got [" + count.count() + "] for index [" + indexName + "]");
            }
        }

        System.out.println("Test end");
        for (Node node : nodes) {
View Full Code Here

                }
            } catch (Exception e) {
                logger.warn("failed to execute cluster health....");
            }

            CountResponse count = client.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            logger.info("*** index_count [{}], expected_count [{}]", count.count(), indexCounter.get());
            // verify count
            for (int i = 0; i < (nodes.length * 5); i++) {
                count = client.client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
                logger.debug("index_count [{}], expected_count [{}]", count.count(), indexCounter.get());
                if (count.count() != indexCounter.get()) {
                    logger.warn("!!! count does not match, index_count [{}], expected_count [{}]", count.count(), indexCounter.get());
                    throw new Exception("failed test, count does not match...");
                }
            }

            // verify search
            for (int i = 0; i < (nodes.length * 5); i++) {
                // do a search with norms field, so we don't rely on match all filtering cache
                SearchResponse search = client.client().prepareSearch().setQuery(matchAllQuery().normsField("field")).execute().actionGet();
                logger.debug("index_count [{}], expected_count [{}]", search.hits().totalHits(), indexCounter.get());
                if (count.count() != indexCounter.get()) {
                    logger.warn("!!! search does not match, index_count [{}], expected_count [{}]", search.hits().totalHits(), indexCounter.get());
                    throw new Exception("failed test, count does not match...");
                }
            }

View Full Code Here

        }

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

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(10l));
        }

        ClusterState clusterState = client1.admin().cluster().prepareState().execute().actionGet().state();
        assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true));

        client1.admin().indices().prepareDeleteMapping().setType("type1").execute().actionGet();
        Thread.sleep(500); // for now, we don't have ack logic, so just wait

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(0l));
        }

        clusterState = client1.admin().cluster().prepareState().execute().actionGet().state();
        assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(false));
    }
View Full Code Here

        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));
View Full Code Here

        }

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

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(10l));
        }

        logger.info("Increasing the number of replicas from 1 to 2");
        client1.admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("index.number_of_replicas", 2)).execute().actionGet();
        Thread.sleep(200);

        logger.info("Running Cluster Health");
        clusterHealth = client1.admin().cluster().prepareHealth().setWaitForYellowStatus().setWaitForActiveShards(10).execute().actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.YELLOW));
        assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
        assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(2));
        assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(10));

        logger.info("starting another node to new replicas will be allocated to it");
        startNode("node3");
        Thread.sleep(100);

        logger.info("Running Cluster Health");
        clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").execute().actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
        assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(2));
        assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(15));

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.count(), equalTo(10l));
        }

        logger.info("Decreasing number of replicas from 2 to 0");
        client1.admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder().put("index.number_of_replicas", 0)).execute().actionGet();
        Thread.sleep(200);

        logger.info("Running Cluster Health");
        clusterHealth = client1.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("3").execute().actionGet();
        logger.info("Done Cluster Health, status " + clusterHealth.status());
        assertThat(clusterHealth.timedOut(), equalTo(false));
        assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
        assertThat(clusterHealth.indices().get("test").activePrimaryShards(), equalTo(5));
        assertThat(clusterHealth.indices().get("test").numberOfReplicas(), equalTo(0));
        assertThat(clusterHealth.indices().get("test").activeShards(), equalTo(5));

        for (int i = 0; i < 10; i++) {
            CountResponse countResponse = client1.prepareCount().setQuery(matchAllQuery()).execute().actionGet();
            assertThat(countResponse.shardFailures().toString(), countResponse.failedShards(), equalTo(0));
            assertThat(countResponse.count(), equalTo(10l));
        }
    }
View Full Code Here

        node.client().index(indexRequest("test").type("person")
                .source(jsonBuilder().startObject().field("file", html).endObject())).actionGet();
        node.client().admin().indices().refresh(refreshRequest()).actionGet();

        CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file.title", "test document"))).actionGet();
        assertThat(countResponse.count(), equalTo(1l));

        countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "tests the ability"))).actionGet();
        assertThat(countResponse.count(), equalTo(1l));
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.count.CountResponse

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.