use of org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder in project OpenSearch by opensearch-project.
the class IndexStatsIT method testMultiIndex.
public void testMultiIndex() throws Exception {
assertAcked(prepareCreate("test1"));
createIndex("test2");
ensureGreen();
client().prepareIndex("test1").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1").setId(Integer.toString(2)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test2").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
refresh();
int numShards1 = getNumShards("test1").totalNumShards;
int numShards2 = getNumShards("test2").totalNumShards;
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("_all").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("_all").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("*").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("test1").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1));
stats = builder.setIndices("test1", "test2").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards1 + numShards2));
stats = builder.setIndices("*2").execute().actionGet();
assertThat(stats.getTotalShards(), equalTo(numShards2));
}
use of org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder in project OpenSearch by opensearch-project.
the class IndexStatsIT method testCompletionFieldsParam.
public void testCompletionFieldsParam() throws Exception {
assertAcked(prepareCreate("test1").addMapping("_doc", "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}" + ",\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON));
ensureGreen();
client().prepareIndex("test1").setId(Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
refresh();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();
assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields(), is(nullValue()));
stats = builder.setCompletionFields("bar.completion").execute().actionGet();
assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(false));
stats = builder.setCompletionFields("bar.completion", "baz.completion").execute().actionGet();
assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("baz.completion"), greaterThan(0L));
stats = builder.setCompletionFields("*").execute().actionGet();
assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("baz.completion"), greaterThan(0L));
stats = builder.setCompletionFields("*r*").execute().actionGet();
assertThat(stats.getTotal().completion.getSizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("bar.completion"), is(true));
assertThat(stats.getTotal().completion.getFields().get("bar.completion"), greaterThan(0L));
assertThat(stats.getTotal().completion.getFields().containsField("baz.completion"), is(false));
}
use of org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder in project OpenSearch by opensearch-project.
the class IndexStatsIT method testGroupsParam.
public void testGroupsParam() throws Exception {
createIndex("test1");
ensureGreen();
client().prepareIndex("test1").setId(Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
refresh();
client().prepareSearch("_all").setStats("bar", "baz").execute().actionGet();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();
assertThat(stats.getTotal().search.getTotal().getQueryCount(), greaterThan(0L));
assertThat(stats.getTotal().search.getGroupStats(), is(nullValue()));
stats = builder.setGroups("bar").execute().actionGet();
assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
assertThat(stats.getTotal().search.getGroupStats().containsKey("baz"), is(false));
stats = builder.setGroups("bar", "baz").execute().actionGet();
assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
assertThat(stats.getTotal().search.getGroupStats().get("baz").getQueryCount(), greaterThan(0L));
stats = builder.setGroups("*").execute().actionGet();
assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
assertThat(stats.getTotal().search.getGroupStats().get("baz").getQueryCount(), greaterThan(0L));
stats = builder.setGroups("*r").execute().actionGet();
assertThat(stats.getTotal().search.getGroupStats().get("bar").getQueryCount(), greaterThan(0L));
assertThat(stats.getTotal().search.getGroupStats().containsKey("baz"), is(false));
}
use of org.opensearch.action.admin.indices.stats.IndicesStatsRequestBuilder in project OpenSearch by opensearch-project.
the class IndexStatsIT method testAllFlags.
public void testAllFlags() throws Exception {
// rely on 1 replica for this tests
assertAcked(prepareCreate("test_index"));
createIndex("test_index_2");
ensureGreen();
client().prepareIndex("test_index").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test_index").setId(Integer.toString(2)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test_index_2").setId(Integer.toString(1)).setSource("field", "value").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
Flag[] values = CommonStatsFlags.Flag.values();
for (Flag flag : values) {
set(flag, builder, false);
}
IndicesStatsResponse stats = builder.execute().actionGet();
for (Flag flag : values) {
assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
assertThat(isSet(flag, stats.getTotal()), equalTo(false));
}
for (Flag flag : values) {
set(flag, builder, true);
}
stats = builder.execute().actionGet();
for (Flag flag : values) {
assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
assertThat(isSet(flag, stats.getTotal()), equalTo(true));
}
Random random = random();
EnumSet<Flag> flags = EnumSet.noneOf(Flag.class);
for (Flag flag : values) {
if (random.nextBoolean()) {
flags.add(flag);
}
}
for (Flag flag : values) {
// clear all
set(flag, builder, false);
}
for (Flag flag : flags) {
// set the flags
set(flag, builder, true);
}
stats = builder.execute().actionGet();
for (Flag flag : flags) {
// check the flags
assertThat(isSet(flag, stats.getPrimaries()), equalTo(true));
assertThat(isSet(flag, stats.getTotal()), equalTo(true));
}
for (Flag flag : EnumSet.complementOf(flags)) {
// check the complement
assertThat(isSet(flag, stats.getPrimaries()), equalTo(false));
assertThat(isSet(flag, stats.getTotal()), equalTo(false));
}
}
Aggregations