Examples of CountResponse


Examples of org.elasticsearch.action.count.CountResponse

        logger.info("Count");
        // check count
        for (int i = 0; i < 5; i++) {
            // test successful
            CountResponse countResponse = client("server1").count(countRequest("test").query(termQuery("_type", "type1")).operationThreading(BroadcastOperationThreading.NO_THREADS)).actionGet();
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.totalShards(), equalTo(5));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));
        }

        for (int i = 0; i < 5; i++) {
            CountResponse countResponse = client("server1").count(countRequest("test").query(termQuery("_type", "type1")).operationThreading(BroadcastOperationThreading.SINGLE_THREAD)).actionGet();
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.totalShards(), equalTo(5));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));
        }

        for (int i = 0; i < 5; i++) {
            CountResponse countResponse = client("server1").count(countRequest("test").query(termQuery("_type", "type1")).operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD)).actionGet();
            assertThat(countResponse.count(), equalTo(2l));
            assertThat(countResponse.totalShards(), equalTo(5));
            assertThat(countResponse.successfulShards(), equalTo(5));
            assertThat(countResponse.failedShards(), equalTo(0));
        }

        for (int i = 0; i < 5; i++) {
            // test failed (simply query that can't be parsed)
            CountResponse countResponse = client("server1").count(countRequest("test").query(Unicode.fromStringAsBytes("{ term : { _type : \"type1 } }"))).actionGet();

            assertThat(countResponse.count(), equalTo(0l));
            assertThat(countResponse.totalShards(), equalTo(5));
            assertThat(countResponse.successfulShards(), equalTo(0));
            assertThat(countResponse.failedShards(), equalTo(5));
            for (ShardOperationFailedException exp : countResponse.shardFailures()) {
                assertThat(exp.reason(), containsString("QueryParsingException"));
            }
        }

    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();

        index("test", "person", jsonBuilder().startObject().field("file", html).endObject());
        refresh();

        CountResponse countResponse = client().prepareCount("test").setQuery(queryString("test document").defaultField("file.title")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));

        countResponse = client().prepareCount("test").setQuery(queryString("tests the ability").defaultField("file")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();

        index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
        refresh();

        CountResponse countResponse = client().prepareCount("test").setQuery(queryString("BeforeLimit").defaultField("file")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));

        countResponse = client().prepareCount("test").setQuery(queryString("AfterLimit").defaultField("file")).execute().get();
        assertThat(countResponse.getCount(), equalTo(0l));
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();

        index("test", "person", jsonBuilder().startObject().field("file").startObject().field("_content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
        refresh();

        CountResponse countResponse = client().prepareCount("test").setQuery(queryString("Begin").defaultField("file")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));

        countResponse = client().prepareCount("test").setQuery(queryString("End").defaultField("file")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        index("test", "person", jsonBuilder().startObject().field("file1", html).field("file2", pdf).field("hello","world").endObject());
        refresh();


        CountResponse countResponse = client().prepareCount("test").setQuery(queryString("World").defaultField("file1")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));

        countResponse = client().prepareCount("test").setQuery(queryString("World").defaultField("hello")).execute().get();
        assertThat(countResponse.getCount(), equalTo(1l));
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

            // Log
            LOGGER.debug( "Will count Entities: {}", request );

            // Execute
            CountResponse count = request.execute().actionGet();

            return count.getCount();
        }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        RefreshResponse rsp = client.admin().indices().refresh(new RefreshRequest(indices)).actionGet();
        //assertEquals(1, rsp.getFailedShards());
    }

    public long countAll() {
        CountResponse response = client.prepareCount(getIndexName()).
                setQuery(QueryBuilders.matchAllQuery()).
                execute().actionGet();
        return response.getCount();
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

    public long countAll() {
        return countAll(getIndexName());
    }

    public long countAll(String... indices) {
        CountResponse response = client.prepareCount(indices).
                setQuery(QueryBuilders.matchAllQuery()).
                execute().actionGet();
        return response.getCount();
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

                if (source == null) {
                    query = QueryBuilders.matchAllQuery();
                } else {
                    query = QueryBuilders.queryString(source).defaultField("feedname");
                }
                CountResponse response = client().prepareCount(index)
                        .setQuery(query).execute().actionGet();
                return response.getCount() > 0;
            }
        }, 10, TimeUnit.SECONDS), equalTo(true));
    }
View Full Code Here

Examples of org.elasticsearch.action.count.CountResponse

        String index = "topic";

        createDefaultESSink(index);

        node.client().admin().indices().prepareRefresh(index).execute().actionGet();
        CountResponse response = node.client().prepareCount(index).execute().actionGet();
        assertEquals(response.getCount(), 100);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.