当前位置: 首页>>代码示例>>Java>>正文


Java ElasticsearchParseException类代码示例

本文整理汇总了Java中org.elasticsearch.ElasticsearchParseException的典型用法代码示例。如果您正苦于以下问题:Java ElasticsearchParseException类的具体用法?Java ElasticsearchParseException怎么用?Java ElasticsearchParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ElasticsearchParseException类属于org.elasticsearch包,在下文中一共展示了ElasticsearchParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
@Override
public void execute(IngestDocument document) throws Exception {
    String stringValue = document.getFieldValue(field, String.class);
    try {
        Map<String, Object> mapValue = XContentHelper.convertToMap(JsonXContent.jsonXContent, stringValue, false);
        if (addToRoot) {
            for (Map.Entry<String, Object> entry : mapValue.entrySet()) {
                document.setFieldValue(entry.getKey(), entry.getValue());
            }
        } else {
            document.setFieldValue(targetField, mapValue);
        }
    } catch (ElasticsearchParseException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:JsonProcessor.java

示例2: loadMappings

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public static SortedMap<String, ContextMapping> loadMappings(Object configuration, Version indexVersionCreated)
        throws ElasticsearchParseException {
    if (configuration instanceof Map) {
        Map<String, Object> configurations = (Map<String, Object>)configuration;
        SortedMap<String, ContextMapping> mappings = Maps.newTreeMap();
        for (Entry<String,Object> config : configurations.entrySet()) {
            String name = config.getKey();
            mappings.put(name, loadMapping(name, (Map<String, Object>) config.getValue(), indexVersionCreated));
        }
        return mappings;
    } else if (configuration == null) {
        return ContextMapping.EMPTY_MAPPING;
    } else {
        throw new ElasticsearchParseException("no valid context configuration");
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:ContextBuilder.java

示例3: testPutWithErrorResponse

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public void testPutWithErrorResponse() {
    String id = "_id";
    Pipeline pipeline = store.get(id);
    assertThat(pipeline, nullValue());
    ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();

    PutPipelineRequest putRequest =
        new PutPipelineRequest(id, new BytesArray("{\"description\": \"empty processors\"}"), XContentType.JSON);
    ClusterState previousClusterState = clusterState;
    clusterState = store.innerPut(putRequest, clusterState);
    try {
        store.innerUpdatePipelines(previousClusterState, clusterState);
        fail("should fail");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), equalTo("[processors] required property is missing"));
    }
    pipeline = store.get(id);
    assertThat(pipeline, nullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:PipelineStoreTests.java

示例4: testBuildWithCountryDbAndCityFields

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public void testBuildWithCountryDbAndCityFields() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders);
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-Country.mmdb.gz");
    EnumSet<GeoIpProcessor.Property> cityOnlyProperties = EnumSet.complementOf(GeoIpProcessor.Property.ALL_COUNTRY_PROPERTIES);
    String cityProperty = RandomPicks.randomFrom(Randomness.get(), cityOnlyProperties).toString();
    config.put("properties", Collections.singletonList(cityProperty));
    try {
        factory.create(null, null, config);
        fail("Exception expected");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), equalTo("[properties] illegal property value [" + cityProperty +
                "]. valid values are [IP, COUNTRY_ISO_CODE, COUNTRY_NAME, CONTINENT_NAME]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:GeoIpProcessorFactoryTests.java

示例5: testCreateWithTooManyProcessorTypes

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public void testCreateWithTooManyProcessorTypes() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> { });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_first", (r, t, c) -> processor);
    registry.put("_second", (r, t, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory();

    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    Map<String, Object> processorTypes = new HashMap<>();
    processorTypes.put("_first", Collections.emptyMap());
    processorTypes.put("_second", Collections.emptyMap());
    config.put("processor", processorTypes);
    Exception exception = expectThrows(ElasticsearchParseException.class, () -> forEachFactory.create(registry, null, config));
    assertThat(exception.getMessage(), equalTo("[processor] Must specify exactly one processor type"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ForEachProcessorFactoryTests.java

示例6: testValidate

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public void testValidate() throws Exception {
    PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray(
            "{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\", \"tag\": \"tag1\"}}," +
                "{\"remove\" : {\"field\": \"_field\", \"tag\": \"tag2\"}}]}"),
        XContentType.JSON);

    DiscoveryNode node1 = new DiscoveryNode("_node_id1", buildNewFakeTransportAddress(),
            emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_node_id2", buildNewFakeTransportAddress(),
            emptyMap(), emptySet(), Version.CURRENT);
    Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>();
    ingestInfos.put(node1, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"))));

    ElasticsearchParseException e =
        expectThrows(ElasticsearchParseException.class, () -> store.validatePipeline(ingestInfos, putRequest));
    assertEquals("Processor type [remove] is not installed on node [" + node2 + "]", e.getMessage());
    assertEquals("remove", e.getHeader("processor_type").get(0));
    assertEquals("tag2", e.getHeader("processor_tag").get(0));

    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    store.validatePipeline(ingestInfos, putRequest);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:PipelineStoreTests.java

示例7: incompatibleSnapshotsFromXContent

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
/**
 * Reads the incompatible snapshot ids from x-content, loading them into a new instance of {@link RepositoryData}
 * that is created from the invoking instance, plus the incompatible snapshots that are read from x-content.
 */
public RepositoryData incompatibleSnapshotsFromXContent(final XContentParser parser) throws IOException {
    List<SnapshotId> incompatibleSnapshotIds = new ArrayList<>();
    if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
        while (parser.nextToken() == XContentParser.Token.FIELD_NAME) {
            String currentFieldName = parser.currentName();
            if (INCOMPATIBLE_SNAPSHOTS.equals(currentFieldName)) {
                if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
                    while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
                        incompatibleSnapshotIds.add(SnapshotId.fromXContent(parser));
                    }
                } else {
                    throw new ElasticsearchParseException("expected array for [" + currentFieldName + "]");
                }
            } else {
                throw new ElasticsearchParseException("unknown field name  [" + currentFieldName + "]");
            }
        }
    } else {
        throw new ElasticsearchParseException("start object expected");
    }
    return new RepositoryData(this.genId, this.snapshotIds, this.indexSnapshots, incompatibleSnapshotIds);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RepositoryData.java

示例8: detectInnerMapper

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
private static Mapper.Builder<?, ?> detectInnerMapper(ParseContext parseContext,
                                                      String fieldName, XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    if (token == XContentParser.Token.START_ARRAY) {
        token = parser.nextToken();
    }

    // can't use nulls to detect type
    while (token == XContentParser.Token.VALUE_NULL) {
        token = parser.nextToken();
    }

    if (token == XContentParser.Token.START_ARRAY) {
        throw new ElasticsearchParseException("nested arrays are not supported");
    } else if (token == XContentParser.Token.END_ARRAY) {
        // array is empty or has only null values
        return null;
    }

    return DocumentParser.createBuilderFromDynamicValue(parseContext, token, fieldName);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:ArrayMapper.java

示例9: load

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
private static ContextMapping load(Map<String, Object> contextConfig, Version indexVersionCreated) {
    String name = extractRequiredValue(contextConfig, FIELD_NAME);
    String type = extractRequiredValue(contextConfig, FIELD_TYPE);
    final ContextMapping contextMapping;
    switch (Type.fromString(type)) {
        case CATEGORY:
            contextMapping = CategoryContextMapping.load(name, contextConfig);
            break;
        case GEO:
            contextMapping = GeoContextMapping.load(name, contextConfig);
            break;
        default:
            throw new ElasticsearchParseException("unknown context type[" + type + "]");
    }
    DocumentMapperParser.checkNoRemainingFields(name, contextConfig, indexVersionCreated);
    return contextMapping;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ContextMappings.java

示例10: parseRequest

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
/**
 * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
 */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
    MultiSearchRequest multiRequest = new MultiSearchRequest();
    if (restRequest.hasParam("max_concurrent_searches")) {
        multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
    }

    parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
        try {
            final QueryParseContext queryParseContext = new QueryParseContext(parser);
            searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext));
            multiRequest.add(searchRequest);
        } catch (IOException e) {
            throw new ElasticsearchParseException("Exception when parsing search request", e);
        }
    });

    return multiRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RestMultiSearchAction.java

示例11: parseFetchedDoc

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
private ParsedDocument parseFetchedDoc(PercolateContext context, BytesReference fetchedDoc, IndexService documentIndexService, String index, String type) {
    ParsedDocument doc = null;
    XContentParser parser = null;
    try {
        parser = XContentFactory.xContent(fetchedDoc).createParser(fetchedDoc);
        MapperService mapperService = documentIndexService.mapperService();
        DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
        doc = docMapper.getDocumentMapper().parse(source(parser).index(index).type(type).flyweight(true));

        if (context.highlight() != null) {
            doc.setSource(fetchedDoc);
        }
    } catch (Throwable e) {
        throw new ElasticsearchParseException("failed to parse request", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }

    if (doc == null) {
        throw new ElasticsearchParseException("No doc to percolate in the request");
    }

    return doc;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:PercolatorService.java

示例12: parseGeometries

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
/**
 * Parse the geometries array of a GeometryCollection
 *
 * @param parser Parser that will be read from
 * @return Geometry[] geometries of the GeometryCollection
 * @throws IOException Thrown if an error occurs while reading from the XContentParser
 */
protected static GeometryCollectionBuilder parseGeometries(XContentParser parser, GeoShapeFieldMapper mapper) throws
        IOException {
    if (parser.currentToken() != XContentParser.Token.START_ARRAY) {
        throw new ElasticsearchParseException("geometries must be an array of geojson objects");
    }

    XContentParser.Token token = parser.nextToken();
    GeometryCollectionBuilder geometryCollection = newGeometryCollection( (mapper == null) ? Orientation.RIGHT : mapper
            .fieldType().orientation());
    while (token != XContentParser.Token.END_ARRAY) {
        ShapeBuilder shapeBuilder = GeoShapeType.parse(parser);
        geometryCollection.shape(shapeBuilder);
        token = parser.nextToken();
    }

    return geometryCollection;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:ShapeBuilder.java

示例13: parseLineString

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
protected static LineStringBuilder parseLineString(CoordinateNode coordinates) {
    /**
     * Per GeoJSON spec (http://geojson.org/geojson-spec.html#linestring)
     * "coordinates" member must be an array of two or more positions
     * LineStringBuilder should throw a graceful exception if < 2 coordinates/points are provided
     */
    if (coordinates.children.size() < 2) {
        throw new ElasticsearchParseException("invalid number of points in LineString (found [{}] - must be >= 2)", coordinates.children.size());
    }

    LineStringBuilder line = newLineString();
    for (CoordinateNode node : coordinates.children) {
        line.point(node.coordinate);
    }
    return line;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:ShapeBuilder.java

示例14: testMatchFormatsIsMandatory

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
public void testMatchFormatsIsMandatory() throws Exception {
    DateProcessor.Factory factory = new DateProcessor.Factory();
    Map<String, Object> config = new HashMap<>();
    String sourceField = randomAsciiOfLengthBetween(1, 10);
    String targetField = randomAsciiOfLengthBetween(1, 10);
    config.put("field", sourceField);
    config.put("target_field", targetField);

    try {
        factory.create(null, null, config);
        fail("processor creation should have failed");
    } catch(ElasticsearchParseException e) {
        assertThat(e.getMessage(), containsString("[formats] required property is missing"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:DateProcessorFactoryTests.java

示例15: parseArrayToSet

import org.elasticsearch.ElasticsearchParseException; //导入依赖的package包/类
private Set<BytesRef> parseArrayToSet(XContentParser parser) throws IOException {
    final Set<BytesRef> set = new HashSet<>();
    if (parser.currentToken() != XContentParser.Token.START_ARRAY) {
        throw new ElasticsearchParseException("Missing start of array in include/exclude clause");
    }
    while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
        if (!parser.currentToken().isValue()) {
            throw new ElasticsearchParseException("Array elements in include/exclude clauses should be string values");
        }
        set.add(new BytesRef(parser.text()));
    }
    return set;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:IncludeExclude.java


注:本文中的org.elasticsearch.ElasticsearchParseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。