// client.admin().indices().prepareFlush().setRefresh(true).execute().actionGet();
client.admin().indices().prepareRefresh().execute().actionGet();
// STRING
SearchResponse searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("str_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(searchResponse.hits().getAt(i).sortValues()[0].toString(), equalTo(new String(new char[]{(char) (97 + i), (char) (97 + i)})));
}
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("str_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(searchResponse.hits().getAt(i).sortValues()[0].toString(), equalTo(new String(new char[]{(char) (97 + (9 - i)), (char) (97 + (9 - i))})));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// BYTE
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("byte_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).byteValue(), equalTo((byte) i));
}
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("byte_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).byteValue(), equalTo((byte) (9 - i)));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// SHORT
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("short_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).shortValue(), equalTo((short) i));
}
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("short_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).shortValue(), equalTo((short) (9 - i)));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// INTEGER
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("integer_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).intValue(), equalTo((int) i));
}
assertThat(searchResponse.toString(), not(containsString("error")));
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("integer_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).intValue(), equalTo((int) (9 - i)));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// LONG
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("long_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).longValue(), equalTo((long) i));
}
assertThat(searchResponse.toString(), not(containsString("error")));
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("long_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).longValue(), equalTo((long) (9 - i)));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// FLOAT
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("float_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).doubleValue(), closeTo(0.1d * i, 0.000001d));
}
assertThat(searchResponse.toString(), not(containsString("error")));
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("float_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).doubleValue(), closeTo(0.1d * (9 - i), 0.000001d));
}
assertThat(searchResponse.toString(), not(containsString("error")));
// DOUBLE
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("double_value", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).doubleValue(), closeTo(0.1d * i, 0.000001d));
}
assertThat(searchResponse.toString(), not(containsString("error")));
searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(10)
.addSort("double_value", SortOrder.DESC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(10l));
assertThat(searchResponse.hits().hits().length, equalTo(10));
for (int i = 0; i < 10; i++) {
assertThat(searchResponse.hits().getAt(i).id(), equalTo(Integer.toString(9 - i)));
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).doubleValue(), closeTo(0.1d * (9 - i), 0.000001d));
}
assertThat(searchResponse.toString(), not(containsString("error")));
}