Bug: Sort on a column of type 'short' throws an exception, closes #835.
This commit is contained in:
parent
4721f9aa69
commit
35be46df71
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.facet.Facets;
|
||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||
|
@ -295,4 +296,16 @@ public class SearchResponse implements ActionResponse, ToXContent {
|
|||
}
|
||||
out.writeVLong(tookInMillis);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
try {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
||||
builder.startObject();
|
||||
toXContent(builder, EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
return builder.string();
|
||||
} catch (IOException e) {
|
||||
return "{ \"error\" : \"" + e.getMessage() + "\"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -577,6 +577,10 @@ public final class XContentBuilder {
|
|||
field(name, ((Integer) value).intValue());
|
||||
} else if (type == Long.class) {
|
||||
field(name, ((Long) value).longValue());
|
||||
} else if (type == Short.class) {
|
||||
field(name, ((Short) value).shortValue());
|
||||
} else if (type == Byte.class) {
|
||||
field(name, ((Byte) value).byteValue());
|
||||
} else if (type == Boolean.class) {
|
||||
field(name, ((Boolean) value).booleanValue());
|
||||
} else if (type == Date.class) {
|
||||
|
@ -624,6 +628,10 @@ public final class XContentBuilder {
|
|||
field(name, ((Integer) value).intValue());
|
||||
} else if (type == Long.class) {
|
||||
field(name, ((Long) value).longValue());
|
||||
} else if (type == Short.class) {
|
||||
field(name, ((Short) value).shortValue());
|
||||
} else if (type == Byte.class) {
|
||||
field(name, ((Byte) value).byteValue());
|
||||
} else if (type == Boolean.class) {
|
||||
field(name, ((Boolean) value).booleanValue());
|
||||
} else if (type == Date.class) {
|
||||
|
@ -668,6 +676,10 @@ public final class XContentBuilder {
|
|||
value(((Integer) value).intValue());
|
||||
} else if (type == Long.class) {
|
||||
value(((Long) value).longValue());
|
||||
} else if (type == Short.class) {
|
||||
value(((Short) value).shortValue());
|
||||
} else if (type == Byte.class) {
|
||||
value(((Byte) value).byteValue());
|
||||
} else if (type == Boolean.class) {
|
||||
value((Boolean) value);
|
||||
} else if (type == byte[].class) {
|
||||
|
|
|
@ -189,6 +189,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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()
|
||||
|
@ -217,6 +219,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).byteValue(), equalTo((byte) (9 - i)));
|
||||
}
|
||||
|
||||
assertThat(searchResponse.toString(), not(containsString("error")));
|
||||
|
||||
// SHORT
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
|
@ -245,6 +249,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).shortValue(), equalTo((short) (9 - i)));
|
||||
}
|
||||
|
||||
assertThat(searchResponse.toString(), not(containsString("error")));
|
||||
|
||||
// INTEGER
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
|
@ -260,6 +266,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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)
|
||||
|
@ -273,6 +281,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).intValue(), equalTo((int) (9 - i)));
|
||||
}
|
||||
|
||||
assertThat(searchResponse.toString(), not(containsString("error")));
|
||||
|
||||
// LONG
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
|
@ -288,6 +298,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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)
|
||||
|
@ -301,6 +313,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
assertThat(((Number) searchResponse.hits().getAt(i).sortValues()[0]).longValue(), equalTo((long) (9 - i)));
|
||||
}
|
||||
|
||||
assertThat(searchResponse.toString(), not(containsString("error")));
|
||||
|
||||
// FLOAT
|
||||
|
||||
searchResponse = client.prepareSearch()
|
||||
|
@ -316,6 +330,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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)
|
||||
|
@ -329,6 +345,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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()
|
||||
|
@ -344,6 +362,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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)
|
||||
|
@ -356,6 +376,8 @@ public class SimpleSortTests extends AbstractNodesTests {
|
|||
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")));
|
||||
}
|
||||
|
||||
@Test public void testDocumentsWithNullValue() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue