org.elasticsearch.index.mapper.MapperParsingException Java Examples

The following examples show how to use org.elasticsearch.index.mapper.MapperParsingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IdFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    XContentParser parser = context.parser();
    if (parser.currentName() != null && parser.currentName().equals(Defaults.NAME) && parser.currentToken().isValue()) {
        // we are in the parse Phase
        String id = parser.text();
        if (context.id() != null && !context.id().equals(id)) {
            throw new MapperParsingException("Provided id [" + context.id() + "] does not match the content one [" + id + "]");
        }
        context.id(id);
    } // else we are in the pre/post parse phase

    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        fields.add(new Field(fieldType().names().indexName(), context.id(), fieldType()));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new BinaryDocValuesField(fieldType().names().indexName(), new BytesRef(context.id())));
    }
}
 
Example #2
Source File: TTLFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder();
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            EnabledAttributeMapper enabledState = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
            builder.enabled(enabledState);
            iterator.remove();
        } else if (fieldName.equals("default")) {
            TimeValue ttlTimeValue = nodeTimeValue(fieldNode, null);
            if (ttlTimeValue != null) {
                builder.defaultTTL(ttlTimeValue.millis());
            }
            iterator.remove();
        }
    }
    return builder;
}
 
Example #3
Source File: IndexFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        return builder;
    }

    parseField(builder, builder.name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            EnabledAttributeMapper mapper = nodeBooleanValue(fieldNode) ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED;
            builder.enabled(mapper);
            iterator.remove();
        }
    }
    return builder;
}
 
Example #4
Source File: RoutingFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("required")) {
            builder.required(nodeBooleanValue(fieldNode));
            iterator.remove();
        } else if (fieldName.equals("path") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            builder.path(fieldNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #5
Source File: FieldNamesFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().before(Version.V_1_3_0)) {
        throw new IllegalArgumentException("type="+CONTENT_TYPE+" is not supported on indices created before version 1.3.0. Is your cluster running multiple datanode versions?");
    }
    
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
        parseField(builder, builder.name, node, parserContext);
    }

    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("enabled")) {
            builder.enabled(nodeBooleanValue(fieldNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #6
Source File: VersionFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder<?, ?> parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder();
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        if (fieldName.equals("doc_values_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // ignore in 1.x, reject in 2.x
            iterator.remove();
        } else if (fieldName.equals("path")) {
            builder.path(entry.getValue().toString());
            iterator.remove();
        } else if (fieldName.equals("version_type")) {
            builder.versionType(entry.getValue().toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #7
Source File: IdFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) {
        throw new MapperParsingException(NAME + " is not configurable");
    }
    Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
    parseField(builder, builder.name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("path")) {
            builder.path(fieldNode.toString());
            iterator.remove();
        }
    }
    return builder;
}
 
Example #8
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_putMappingメソッドで初回にMapperParsingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_putMappingメソッドで初回にMapperParsingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncPutMapping()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncPutMapping(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.putMapping(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsSchemaMismatchException e) {
        assertTrue(e.getCause() instanceof MapperParsingException);
    }
}
 
Example #9
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること.
 */
@Test(expected = EsClientException.EsSchemaMismatchException.class)
public void ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", new HashMap<Object, Object>());
    fail("EsSchemaMismatchException should be thrown.");
}
 
Example #10
Source File: MinHashFieldMapper.java    From elasticsearch-minhash with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(final String name, final Map<String, Object> node,
        final ParserContext parserContext) throws MapperParsingException {
    final MinHashFieldMapper.Builder builder = new MinHashFieldMapper.Builder(
            name);
    parseField(builder, name, node, parserContext);
    for (final Iterator<Map.Entry<String, Object>> iterator = node.entrySet()
            .iterator(); iterator.hasNext();) {
        final Map.Entry<String, Object> entry = iterator.next();
        final String propName = entry.getKey();
        final Object propNode = entry.getValue();
        if (propName.equals("minhash_analyzer") && propNode != null) {
            final NamedAnalyzer analyzer = parserContext
                    .getIndexAnalyzers().get(propNode.toString());
            builder.minhashAnalyzer(analyzer);
            iterator.remove();
        } else if (propName.equals("copy_bits_to")
                && propNode != null) {
            parseCopyBitsFields(propNode, builder);
            iterator.remove();
        }
    }
    return builder;
}
 
Example #11
Source File: ByteFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    ByteFieldMapper.Builder builder = byteField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeByteValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #12
Source File: ArrayMapperTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedArrayMapping() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder()
        .startObject().startObject(TYPE).startObject("properties")
        .startObject("array_field")
        .field("type", ArrayMapper.CONTENT_TYPE)
        .startObject(ArrayMapper.INNER_TYPE)
        .field("type", ArrayMapper.CONTENT_TYPE)
        .startObject(ArrayMapper.INNER_TYPE)
        .field("type", "double")
        .endObject()
        .endObject()
        .endObject()
        .endObject().endObject().endObject());

    expectedException.expect(MapperParsingException.class);
    expectedException.expectMessage("nested arrays are not supported");
    mapper(INDEX, mapping);
}
 
Example #13
Source File: MetaDataIndexUpgrader.java    From crate with Apache License 2.0 6 votes vote down vote up
private static void handleDynamicTemplates(LinkedHashMap<String, Object> newMapping, String fieldName, List<?> fieldNode) {
    List<Object> templates = new ArrayList<>();
    for (Object tmplNode : fieldNode) {
        //noinspection unchecked
        Map<String, Object> tmpl = (Map<String, Object>) tmplNode;
        if (tmpl.size() != 1) {
            throw new MapperParsingException("A dynamic template must be defined with a name");
        }
        Map.Entry<String, Object> tmpEntry = tmpl.entrySet().iterator().next();
        String templateName = tmpEntry.getKey();
        if (templateName.equals("strings") == false) {
            templates.add(tmplNode);
        }
    }
    if (templates.size() > 0) {
        newMapping.put(fieldName, templates);
    }
}
 
Example #14
Source File: TypeParsers.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void parseTermVector(String fieldName, String termVector, FieldMapper.Builder builder) throws MapperParsingException {
    termVector = Strings.toUnderscoreCase(termVector);
    if ("no".equals(termVector)) {
        builder.storeTermVectors(false);
    } else if ("yes".equals(termVector)) {
        builder.storeTermVectors(true);
    } else if ("with_offsets".equals(termVector)) {
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions".equals(termVector)) {
        builder.storeTermVectorPositions(true);
    } else if ("with_positions_offsets".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
    } else if ("with_positions_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorPayloads(true);
    } else if ("with_positions_offsets_payloads".equals(termVector)) {
        builder.storeTermVectorPositions(true);
        builder.storeTermVectorOffsets(true);
        builder.storeTermVectorPayloads(true);
    } else {
        throw new MapperParsingException("wrong value for termVector [" + termVector + "] for field [" + fieldName + "]");
    }
}
 
Example #15
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にMapperParsingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にMapperParsingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    (OpType) Mockito.anyObject(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.update("dummyId", null, 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsSchemaMismatchException e) {
        assertTrue(e.getCause() instanceof MapperParsingException);
    }
}
 
Example #16
Source File: IntegerFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    IntegerFieldMapper.Builder builder = integerField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeIntegerValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #17
Source File: ParentFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public ParentFieldMapper build(BuilderContext context) {
    if (parentType == null) {
        throw new MapperParsingException("[_parent] field mapping must contain the [type] option");
    }
    parentJoinFieldType.setNames(new MappedFieldType.Names(joinField(documentType)));
    parentJoinFieldType.setFieldDataType(null);
    childJoinFieldType.setNames(new MappedFieldType.Names(joinField(parentType)));
    if (context.indexCreatedVersion().before(Version.V_2_0_0_beta1)) {
        childJoinFieldType.setHasDocValues(false);
        childJoinFieldType.setDocValuesType(DocValuesType.NONE);
        parentJoinFieldType.setHasDocValues(false);
        parentJoinFieldType.setDocValuesType(DocValuesType.NONE);
    }
    return new ParentFieldMapper(fieldType, parentJoinFieldType, childJoinFieldType, parentType, context.indexSettings());
}
 
Example #18
Source File: ParentFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public MetadataFieldMapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    Builder builder = new Builder(parserContext.type());
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (fieldName.equals("type")) {
            builder.type(fieldNode.toString());
            iterator.remove();
        } else if (fieldName.equals("postings_format") && parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) {
            // ignore before 2.0, reject on and after 2.0
            iterator.remove();
        } else if (fieldName.equals("fielddata")) {
            // Only take over `loading`, since that is the only option now that is configurable:
            Map<String, String> fieldDataSettings = SettingsLoader.Helper.loadNestedFromMap(nodeMapValue(fieldNode, "fielddata"));
            if (fieldDataSettings.containsKey(MappedFieldType.Loading.KEY)) {
                Settings settings = settingsBuilder().put(MappedFieldType.Loading.KEY, fieldDataSettings.get(MappedFieldType.Loading.KEY)).build();
                builder.fieldDataSettings(settings);
            }
            iterator.remove();
        }
    }
    return builder;
}
 
Example #19
Source File: DoubleFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    DoubleFieldMapper.Builder builder = doubleField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = entry.getKey();
        Object propNode = entry.getValue();
        if (propName.equals("nullValue") || propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeDoubleValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #20
Source File: ArrayMapperTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidArrayNonConvertableType() throws Exception {
    String mapping = Strings.toString(XContentFactory.jsonBuilder()
        .startObject().startObject(TYPE).startObject("properties")
        .startObject("array_field")
        .field("type", ArrayMapper.CONTENT_TYPE)
        .startObject(ArrayMapper.INNER_TYPE)
        .field("type", "double")
        .endObject()
        .endObject()
        .endObject().endObject().endObject());
    DocumentMapper mapper = mapper(INDEX, mapping);

    expectedException.expect(MapperParsingException.class);
    expectedException.expectMessage("failed to parse field [array_field] of type [double]");

    BytesReference bytesReference = BytesReference.bytes(XContentFactory.jsonBuilder()
        .startObject()
        .array("array_field", true, false, true)
        .endObject());
    SourceToParse sourceToParse = new SourceToParse(INDEX, "abc", bytesReference, XContentType.JSON);
    mapper.parse(sourceToParse);
}
 
Example #21
Source File: LongFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    LongFieldMapper.Builder builder = longField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeLongValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #22
Source File: EsRetryTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること.
 */
@Test(expected = EsClientException.EsSchemaMismatchException.class)
public void ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", new HashMap<Object, Object>());
    fail("EsSchemaMismatchException should be thrown.");
}
 
Example #23
Source File: EsRetry2Test.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること.
 */
@Test(expected = EsClientException.EsSchemaMismatchException.class)
public void ドキュメント新規作成時_初回でMapperParsingExceptionが発生した場合にEsClient_EsSchemaMismatchExceptionが返されること() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    Mockito.any(OpType.class), Mockito.anyLong());
    // メソッド呼び出し
    esTypeObject.create("dummyId", new HashMap<Object, Object>());
    fail("EsSchemaMismatchException should be thrown.");
}
 
Example #24
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_putMappingメソッドで初回にMapperParsingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_putMappingメソッドで初回にMapperParsingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncPutMapping()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncPutMapping(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.putMapping(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsSchemaMismatchException e) {
        assertTrue(e.getCause() instanceof MapperParsingException);
    }
}
 
Example #25
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にMapperParsingExceptionが投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にMapperParsingExceptionが投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、MapperParsingExceptionを投げる。
    // 送出する例外オブジェクトのモックを作成
    MapperParsingException toBeThrown = Mockito.mock(MapperParsingException.class);
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    (OpType) Mockito.anyObject(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.update("dummyId", null, 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsSchemaMismatchException e) {
        assertTrue(e.getCause() instanceof MapperParsingException);
    }
}
 
Example #26
Source File: RootObjectMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {

    ObjectMapper.Builder builder = createBuilder(name);
    Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, Object> entry = iterator.next();
        String fieldName = Strings.toUnderscoreCase(entry.getKey());
        Object fieldNode = entry.getValue();
        if (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder)
                || processField(builder, fieldName, fieldNode)) {
            iterator.remove();
        }
    }
    return builder;
}
 
Example #27
Source File: BooleanFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    BooleanFieldMapper.Builder builder = booleanField(name);
    parseField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeBooleanValue(propNode));
            iterator.remove();
        } else if (parseMultiField(builder, name, parserContext, propName, propNode)) {
            iterator.remove();
        }
    }
    return builder;
}
 
Example #28
Source File: FloatFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    FloatFieldMapper.Builder builder = floatField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeFloatValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #29
Source File: ShortFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    ShortFieldMapper.Builder builder = shortField(name);
    parseNumberField(builder, name, node, parserContext);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            if (propNode == null) {
                throw new MapperParsingException("Property [null_value] cannot be null.");
            }
            builder.nullValue(nodeShortValue(propNode));
            iterator.remove();
        }
    }
    return builder;
}
 
Example #30
Source File: TokenCountFieldMapper.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
    TokenCountFieldMapper.Builder builder = tokenCountField(name);
    for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, Object> entry = iterator.next();
        String propName = Strings.toUnderscoreCase(entry.getKey());
        Object propNode = entry.getValue();
        if (propName.equals("null_value")) {
            builder.nullValue(nodeIntegerValue(propNode));
            iterator.remove();
        } else if (propName.equals("analyzer")) {
            NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString());
            if (analyzer == null) {
                throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]");
            }
            builder.analyzer(analyzer);
            iterator.remove();
        }
    }
    parseNumberField(builder, name, node, parserContext);
    if (builder.analyzer() == null) {
        throw new MapperParsingException("Analyzer must be set for field [" + name + "] but wasn't.");
    }
    return builder;
}