use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class SourceLookup method loadSourceIfNeeded.
private Map<String, Object> loadSourceIfNeeded() {
if (source != null) {
return source;
}
if (sourceAsBytes != null) {
Tuple<XContentType, Map<String, Object>> tuple = sourceAsMapAndType(sourceAsBytes);
sourceContentType = tuple.v1();
source = tuple.v2();
return source;
}
try {
FieldsVisitor sourceFieldVisitor = new FieldsVisitor(true);
reader.document(docId, sourceFieldVisitor);
BytesReference source = sourceFieldVisitor.source();
if (source == null) {
this.source = emptyMap();
this.sourceContentType = null;
} else {
Tuple<XContentType, Map<String, Object>> tuple = sourceAsMapAndType(source);
this.sourceContentType = tuple.v1();
this.source = tuple.v2();
}
} catch (Exception e) {
throw new ElasticsearchParseException("failed to parse / load source", e);
}
return this.source;
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class SearchSourceBuilderTests method testTimeoutWithoutUnits.
public void testTimeoutWithoutUnits() throws IOException {
final int timeout = randomIntBetween(1, 1024);
final String query = "{ \"query\": { \"match_all\": {}}, \"timeout\": \"" + timeout + "\"}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, query)) {
final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> SearchSourceBuilder.fromXContent(createParseContext(parser)));
assertThat(e, hasToString(containsString("unit is missing or unrecognized")));
}
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class JsonSettingsLoaderTests method testNullValuedSettingThrowsException.
public void testNullValuedSettingThrowsException() {
final String json = "{\"foo\":null}";
final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> new JsonSettingsLoader(false).load(json));
assertThat(e.toString(), containsString("null-valued setting found for key [foo] found at line number [1], column number [8]"));
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class YamlSettingsLoaderTests method testIndentation.
public void testIndentation() throws Exception {
String yaml = "/org/elasticsearch/common/settings/loader/indentation-settings.yml";
ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> {
Settings.builder().loadFromStream(yaml, getClass().getResourceAsStream(yaml));
});
assertTrue(e.getMessage(), e.getMessage().contains("malformed"));
}
use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.
the class YamlSettingsLoaderTests method testIndentationWithExplicitDocumentStart.
public void testIndentationWithExplicitDocumentStart() throws Exception {
String yaml = "/org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml";
ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> {
Settings.builder().loadFromStream(yaml, getClass().getResourceAsStream(yaml));
});
assertTrue(e.getMessage(), e.getMessage().contains("malformed"));
}
Aggregations