Search in sources :

Example 81 with ElasticsearchParseException

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;
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) FieldsVisitor(org.elasticsearch.index.fieldvisitor.FieldsVisitor) XContentType(org.elasticsearch.common.xcontent.XContentType) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) Collections.emptyMap(java.util.Collections.emptyMap) Map(java.util.Map) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 82 with ElasticsearchParseException

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")));
    }
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 83 with ElasticsearchParseException

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]"));
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 84 with ElasticsearchParseException

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"));
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 85 with ElasticsearchParseException

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"));
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Aggregations

ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)106 XContentParser (org.elasticsearch.common.xcontent.XContentParser)44 HashMap (java.util.HashMap)28 ArrayList (java.util.ArrayList)18 IOException (java.io.IOException)13 Map (java.util.Map)11 List (java.util.List)7 GeoPoint (org.elasticsearch.common.geo.GeoPoint)7 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ParsingException (org.elasticsearch.common.ParsingException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)4 Version (org.elasticsearch.Version)4 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)4 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 UncheckedIOException (java.io.UncheckedIOException)3 LinkedHashSet (java.util.LinkedHashSet)3 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)3