Extended mv sorting integration test
This commit is contained in:
parent
8c7779057c
commit
1189a2c2c2
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.search.ShardSearchFailure;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
|
@ -616,18 +617,42 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
.setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0))
|
||||
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("long_values").field("type", "long").endObject()
|
||||
.startObject("int_values").field("type", "integer").endObject()
|
||||
.startObject("short_values").field("type", "short").endObject()
|
||||
.startObject("byte_values").field("type", "byte").endObject()
|
||||
.startObject("float_values").field("type", "float").endObject()
|
||||
.startObject("double_values").field("type", "double").endObject()
|
||||
.startObject("string_values").field("type", "string").field("index", "not_analyzed").endObject()
|
||||
.endObject().endObject().endObject())
|
||||
.execute().actionGet();
|
||||
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
client.prepareIndex("test", "type1", Integer.toString(1)).setSource(jsonBuilder().startObject()
|
||||
.array("long_values", 1l, 5l, 10l, 8l)
|
||||
.array("int_values", 1, 5, 10, 8)
|
||||
.array("short_values", 1, 5, 10, 8)
|
||||
.array("byte_values", 1, 5, 10, 8)
|
||||
.array("float_values", 1f, 5f, 10f, 8f)
|
||||
.array("double_values", 1d, 5d, 10d, 8d)
|
||||
.array("string_values", "01", "05", "10", "08")
|
||||
.endObject()).execute().actionGet();
|
||||
client.prepareIndex("test", "type1", Integer.toString(2)).setSource(jsonBuilder().startObject()
|
||||
.array("long_values", 11l, 15l, 20l, 7l)
|
||||
.array("int_values", 11, 15, 20, 7)
|
||||
.array("short_values", 11, 15, 20, 7)
|
||||
.array("byte_values", 11, 15, 20, 7)
|
||||
.array("float_values", 11f, 15f, 20f, 7f)
|
||||
.array("double_values", 11d, 15d, 20d, 7d)
|
||||
.array("string_values", "11", "15", "20", "07")
|
||||
.endObject()).execute().actionGet();
|
||||
client.prepareIndex("test", "type1", Integer.toString(3)).setSource(jsonBuilder().startObject()
|
||||
.array("long_values", 2l, 1l, 3l, -4l)
|
||||
.array("int_values", 2, 1, 3, -4)
|
||||
.array("short_values", 2, 1, 3, -4)
|
||||
.array("byte_values", 2, 1, 3, -4)
|
||||
.array("float_values", 2f, 1f, 3f, -4f)
|
||||
.array("double_values", 2d, 1d, 3d, -4d)
|
||||
.array("string_values", "02", "01", "03", "!4")
|
||||
.endObject()).execute().actionGet();
|
||||
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
@ -667,6 +692,222 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).longValue(), equalTo(3l));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("int_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(-4));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(1));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(7));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("int_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(20));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(10));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(3));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("short_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(-4));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(1));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(7));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("short_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(20));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(10));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(3));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("byte_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(-4));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(1));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(7));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("byte_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).intValue(), equalTo(20));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).intValue(), equalTo(10));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).intValue(), equalTo(3));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("float_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).floatValue(), equalTo(-4f));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).floatValue(), equalTo(1f));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).floatValue(), equalTo(7f));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("float_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).floatValue(), equalTo(20f));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).floatValue(), equalTo(10f));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).floatValue(), equalTo(3f));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("double_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).doubleValue(), equalTo(-4d));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).doubleValue(), equalTo(1d));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).doubleValue(), equalTo(7d));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("double_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(0).sortValues()[0]).doubleValue(), equalTo(20d));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(1).sortValues()[0]).doubleValue(), equalTo(10d));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Number) searchResponse.hits().getAt(2).sortValues()[0]).doubleValue(), equalTo(3d));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("string_values", SortOrder.ASC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(0).sortValues()[0]).string(), equalTo("!4"));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(1).sortValues()[0]).string(), equalTo("01"));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(2).sortValues()[0]).string(), equalTo("07"));
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
.setQuery(matchAllQuery())
|
||||
.setSize(10)
|
||||
.addSort("string_values", SortOrder.DESC)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(searchResponse.hits().getTotalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(3));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo(Integer.toString(2)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(0).sortValues()[0]).string(), equalTo("20"));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo(Integer.toString(1)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(1).sortValues()[0]).string(), equalTo("10"));
|
||||
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo(Integer.toString(3)));
|
||||
assertThat(((Text) searchResponse.hits().getAt(2).sortValues()[0]).string(), equalTo("03"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue