Merge pull request #15679 from jpountz/fix/text_parsing
Make text parsing less lenient.
This commit is contained in:
commit
c6cf84336f
|
@ -384,7 +384,7 @@ public class GeoUtils {
|
||||||
if(parser.currentToken() == Token.START_OBJECT) {
|
if(parser.currentToken() == Token.START_OBJECT) {
|
||||||
while(parser.nextToken() != Token.END_OBJECT) {
|
while(parser.nextToken() != Token.END_OBJECT) {
|
||||||
if(parser.currentToken() == Token.FIELD_NAME) {
|
if(parser.currentToken() == Token.FIELD_NAME) {
|
||||||
String field = parser.text();
|
String field = parser.currentName();
|
||||||
if(LATITUDE.equals(field)) {
|
if(LATITUDE.equals(field)) {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
switch (parser.currentToken()) {
|
switch (parser.currentToken()) {
|
||||||
|
|
|
@ -34,4 +34,9 @@ public class XContentLocation {
|
||||||
this.lineNumber = lineNumber;
|
this.lineNumber = lineNumber;
|
||||||
this.columnNumber = columnNumber;
|
this.columnNumber = columnNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return lineNumber + ":" + columnNumber;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,11 @@ public class JsonXContentParser extends AbstractXContentParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String text() throws IOException {
|
public String text() throws IOException {
|
||||||
|
if (currentToken().isValue()) {
|
||||||
return parser.getText();
|
return parser.getText();
|
||||||
}
|
}
|
||||||
|
throw new IllegalStateException("Can't get text on a " + currentToken() + " at " + getTokenLocation());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BytesRef utf8Bytes() throws IOException {
|
public BytesRef utf8Bytes() throws IOException {
|
||||||
|
|
|
@ -194,7 +194,7 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||||
protected abstract double doDoubleValue() throws IOException;
|
protected abstract double doDoubleValue() throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String textOrNull() throws IOException {
|
public final String textOrNull() throws IOException {
|
||||||
if (currentToken() == Token.VALUE_NULL) {
|
if (currentToken() == Token.VALUE_NULL) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ public class GeohashCellQuery {
|
||||||
|
|
||||||
while ((token = parser.nextToken()) != Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != Token.END_OBJECT) {
|
||||||
if (token == Token.FIELD_NAME) {
|
if (token == Token.FIELD_NAME) {
|
||||||
String field = parser.text();
|
String field = parser.currentName();
|
||||||
|
|
||||||
if (parseContext.isDeprecatedSetting(field)) {
|
if (parseContext.isDeprecatedSetting(field)) {
|
||||||
// skip
|
// skip
|
||||||
|
|
|
@ -335,43 +335,6 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
|
||||||
assertThat(f.stringValue(), equalTo("-1,-1"));
|
assertThat(f.stringValue(), equalTo("-1,-1"));
|
||||||
assertThat(f.fieldType().stored(), equalTo(false));
|
assertThat(f.fieldType().stored(), equalTo(false));
|
||||||
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
|
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
|
||||||
|
|
||||||
json = jsonBuilder().startObject()
|
|
||||||
.startArray("b").startArray().value(-1).value(-1).endArray().startArray().value(-2).value(-2).endArray().endArray()
|
|
||||||
.endObject().bytes();
|
|
||||||
doc = docMapper.parse("test", "type", "1", json).rootDoc();
|
|
||||||
|
|
||||||
f = doc.getFields("b")[0];
|
|
||||||
assertThat(f, notNullValue());
|
|
||||||
assertThat(f.name(), equalTo("b"));
|
|
||||||
if (indexCreatedBefore22 == true) {
|
|
||||||
assertThat(f.stringValue(), equalTo("-1.0,-1.0"));
|
|
||||||
} else {
|
|
||||||
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-1.0, -1.0)));
|
|
||||||
}
|
|
||||||
assertThat(f.fieldType().stored(), equalTo(stored));
|
|
||||||
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
|
|
||||||
|
|
||||||
f = doc.getFields("b")[1];
|
|
||||||
assertThat(f, notNullValue());
|
|
||||||
assertThat(f.name(), equalTo("b"));
|
|
||||||
if (indexCreatedBefore22 == true) {
|
|
||||||
assertThat(f.stringValue(), equalTo("-2.0,-2.0"));
|
|
||||||
} else {
|
|
||||||
assertThat(Long.parseLong(f.stringValue()), equalTo(GeoUtils.mortonHash(-2.0, -2.0)));
|
|
||||||
}
|
|
||||||
assertThat(f.fieldType().stored(), equalTo(stored));
|
|
||||||
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
|
|
||||||
|
|
||||||
f = doc.getField("b.a");
|
|
||||||
assertThat(f, notNullValue());
|
|
||||||
assertThat(f.name(), equalTo("b.a"));
|
|
||||||
// NOTE: "]" B/c the lat,long aren't specified as a string, we miss the actual values when parsing the multi
|
|
||||||
// fields. We already skipped over the coordinates values and can't get to the coordinates.
|
|
||||||
// This happens if coordinates are specified as array and object.
|
|
||||||
assertThat(f.stringValue(), equalTo("]"));
|
|
||||||
assertThat(f.fieldType().stored(), equalTo(false));
|
|
||||||
assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConvertMultiFieldCompletion() throws Exception {
|
public void testConvertMultiFieldCompletion() throws Exception {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
type: test
|
type: test
|
||||||
id: 1
|
id: 1
|
||||||
body:
|
body:
|
||||||
script:
|
|
||||||
script:
|
script:
|
||||||
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
|
inline: "ctx[\"_source\"][\"myfield\"]=\"bar\""
|
||||||
lang: python
|
lang: python
|
||||||
|
@ -47,7 +46,6 @@
|
||||||
type: test
|
type: test
|
||||||
id: 1
|
id: 1
|
||||||
body:
|
body:
|
||||||
script:
|
|
||||||
script:
|
script:
|
||||||
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
|
inline: "a=42; ctx[\"_source\"][\"myfield\"]=\"bar\""
|
||||||
lang: python
|
lang: python
|
||||||
|
|
Loading…
Reference in New Issue