Skip to content

Commit 46ee7b3

Browse files
authoredJun 19, 2024··
Default analyzer deserialization to custom type when unspecified (#1033) (#1034)
* Default analyzer deserialization to custom type when unspecified Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Add changelog Signed-off-by: Thomas Farr <tsfarr@amazon.com> * Fix for java8 Signed-off-by: Thomas Farr <tsfarr@amazon.com> --------- Signed-off-by: Thomas Farr <tsfarr@amazon.com> (cherry picked from commit 80dc741)

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1414
### Removed
1515

1616
### Fixed
17+
- Fixed error when deserializing an analyzer without `type` specified ([#1033](https://github.com/opensearch-project/opensearch-java/pull/1033))
1718

1819
### Security
1920

‎java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Analyzer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer<Builder> op)
606606
op.add(Builder::smartcn, SmartcnAnalyzer._DESERIALIZER, Kind.Smartcn.jsonValue());
607607
op.add(Builder::cjk, CjkAnalyzer._DESERIALIZER, Kind.Cjk.jsonValue());
608608

609-
op.setTypeProperty("type", null);
609+
op.setTypeProperty("type", Kind.Custom.jsonValue());
610610

611611
}
612612

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.opensearch._types.analysis;
10+
11+
import org.junit.Test;
12+
import org.opensearch.client.opensearch.model.ModelTestCase;
13+
14+
public class AnalyzerDeserializerTest extends ModelTestCase {
15+
@Test
16+
public void deserializesTypelessCustomAnalyzer() {
17+
String json = "{\n"
18+
+ " \"filter\": [\"kuromoji_baseform\", \"ja_stop\"],\n"
19+
+ " \"char_filter\": [\"icu_normalizer\"],\n"
20+
+ " \"tokenizer\": \"kuromoji_tokenizer\"\n"
21+
+ "}";
22+
23+
Analyzer analyzer = fromJson(json, Analyzer._DESERIALIZER);
24+
assertTrue(analyzer.isCustom());
25+
assertEquals("kuromoji_tokenizer", analyzer.custom().tokenizer());
26+
assertEquals("icu_normalizer", analyzer.custom().charFilter().get(0));
27+
assertEquals("kuromoji_baseform", analyzer.custom().filter().get(0));
28+
assertEquals("ja_stop", analyzer.custom().filter().get(1));
29+
}
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.