Fix small bug in routing parsing
This commit is contained in:
parent
591c91a9a9
commit
264efe5478
|
@ -150,12 +150,11 @@ public class MappingMetaData {
|
|||
// And then the value...
|
||||
t = parser.nextToken();
|
||||
if (routingPart.equals(fieldName)) {
|
||||
location++;
|
||||
if (location == routing.pathElements().length) {
|
||||
if (location + 1 == routing.pathElements().length) {
|
||||
return parser.textOrNull();
|
||||
}
|
||||
if (t == XContentParser.Token.START_OBJECT) {
|
||||
return parseRouting(parser, location);
|
||||
return parseRouting(parser, location + 1);
|
||||
}
|
||||
} else {
|
||||
parser.skipChildren();
|
||||
|
|
|
@ -59,4 +59,46 @@ public class ParseRoutingTests {
|
|||
.endObject().copiedBytes();
|
||||
assertThat(md.parseRouting(XContentFactory.xContent(bytes).createParser(bytes)), equalTo("value2"));
|
||||
}
|
||||
|
||||
@Test public void testParseRoutingWithRepeatedField() throws Exception {
|
||||
MappingMetaData md = new MappingMetaData("type1", new CompressedString(""), new MappingMetaData.Routing(true, "field1.field1"));
|
||||
|
||||
byte[] bytes = jsonBuilder().startObject()
|
||||
.field("aaa", "wr")
|
||||
.array("arr1", "1", "2", "3")
|
||||
.field("field1", "foo")
|
||||
.field("field1", "bar")
|
||||
.field("test", "value")
|
||||
.field("zzz", "wr")
|
||||
.endObject().copiedBytes();
|
||||
assertThat(md.parseRouting(XContentFactory.xContent(bytes).createParser(bytes)), equalTo(null));
|
||||
}
|
||||
|
||||
@Test public void testParseRoutingWithRepeatedFieldAndObject() throws Exception {
|
||||
MappingMetaData md = new MappingMetaData("type1", new CompressedString(""), new MappingMetaData.Routing(true, "field1.field1.field2"));
|
||||
|
||||
byte[] bytes = jsonBuilder().startObject()
|
||||
.field("aaa", "wr")
|
||||
.array("arr1", "1", "2", "3")
|
||||
.field("field1", "foo")
|
||||
.startObject("field1").field("field2", "bar").endObject()
|
||||
.field("test", "value")
|
||||
.field("zzz", "wr")
|
||||
.endObject().copiedBytes();
|
||||
assertThat(md.parseRouting(XContentFactory.xContent(bytes).createParser(bytes)), equalTo(null));
|
||||
}
|
||||
|
||||
@Test public void testParseRoutingWithRepeatedFieldAndValidRouting() throws Exception {
|
||||
MappingMetaData md = new MappingMetaData("type1", new CompressedString(""), new MappingMetaData.Routing(true, "field1.field2"));
|
||||
|
||||
byte[] bytes = jsonBuilder().startObject()
|
||||
.field("aaa", "wr")
|
||||
.array("arr1", "1", "2", "3")
|
||||
.field("field1", "foo")
|
||||
.startObject("field1").field("field2", "bar").endObject()
|
||||
.field("test", "value")
|
||||
.field("zzz", "wr")
|
||||
.endObject().copiedBytes();
|
||||
assertThat(md.parseRouting(XContentFactory.xContent(bytes).createParser(bytes)), equalTo("bar"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue