diff --git a/CHANGELOG.md b/CHANGELOG.md index f58a3f30ea..4367749cd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed +- Fixed error when deserializing an analyzer without `type` specified ([#1033](https://github.com/opensearch-project/opensearch-java/pull/1033)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java index 3a60a8daf7..0a0ffd6f4e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java @@ -606,7 +606,7 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer op) op.add(Builder::smartcn, SmartcnAnalyzer._DESERIALIZER, Kind.Smartcn.jsonValue()); op.add(Builder::cjk, CjkAnalyzer._DESERIALIZER, Kind.Cjk.jsonValue()); - op.setTypeProperty("type", null); + op.setTypeProperty("type", Kind.Custom.jsonValue()); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/AnalyzerDeserializerTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/AnalyzerDeserializerTest.java new file mode 100644 index 0000000000..e4a8c21a36 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/AnalyzerDeserializerTest.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch._types.analysis; + +import org.junit.Test; +import org.opensearch.client.opensearch.model.ModelTestCase; + +public class AnalyzerDeserializerTest extends ModelTestCase { + @Test + public void deserializesTypelessCustomAnalyzer() { + String json = "{\n" + + " \"filter\": [\"kuromoji_baseform\", \"ja_stop\"],\n" + + " \"char_filter\": [\"icu_normalizer\"],\n" + + " \"tokenizer\": \"kuromoji_tokenizer\"\n" + + "}"; + + Analyzer analyzer = fromJson(json, Analyzer._DESERIALIZER); + assertTrue(analyzer.isCustom()); + assertEquals("kuromoji_tokenizer", analyzer.custom().tokenizer()); + assertEquals("icu_normalizer", analyzer.custom().charFilter().get(0)); + assertEquals("kuromoji_baseform", analyzer.custom().filter().get(0)); + assertEquals("ja_stop", analyzer.custom().filter().get(1)); + } +}