Skip to content

Commit 0b9456d

Browse files
authored
Add default variant to Analyzer (#522) (#523)
1 parent c7117b4 commit 0b9456d

File tree

2 files changed

+22
-1
lines changed
  • java-client/src

2 files changed

+22
-1
lines changed

java-client/src/main/java/co/elastic/clients/elasticsearch/_types/analysis/Analyzer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer<Builder> op)
628628
builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper));
629629
});
630630

631-
op.setTypeProperty("type", null);
631+
op.setTypeProperty("type", "custom");
632632

633633
}
634634

java-client/src/test/java/co/elastic/clients/elasticsearch/model/VariantsTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package co.elastic.clients.elasticsearch.model;
2121

22+
import co.elastic.clients.elasticsearch._types.analysis.Analyzer;
2223
import co.elastic.clients.elasticsearch._types.mapping.Property;
2324
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
2425
import co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore;
@@ -29,6 +30,8 @@
2930
import co.elastic.clients.json.JsonData;
3031
import org.junit.jupiter.api.Test;
3132

33+
import java.util.function.Consumer;
34+
3235
public class VariantsTest extends ModelTestCase {
3336

3437
@Test
@@ -102,6 +105,24 @@ public void testInternalTag() {
102105
assertTrue(property.ip().fields().get("a-field").float_().coerce());
103106
}
104107

108+
@Test
109+
public void testDefaultInternalTag() {
110+
111+
Consumer<String> test = s -> {
112+
Analyzer a = fromJson(s, Analyzer.class);
113+
assertEquals(Analyzer.Kind.Custom, a._kind());
114+
assertEquals("some-filter", a.custom().filter().get(0));
115+
assertTrue(a.custom().charFilter().isEmpty());
116+
assertEquals("some-tokenizer", a.custom().tokenizer());
117+
};
118+
119+
// Explicit type
120+
test.accept("{\"type\":\"custom\",\"filter\":[\"some-filter\"],\"tokenizer\":\"some-tokenizer\"}");
121+
122+
// Default type
123+
test.accept("{\"filter\":[\"some-filter\"],\"tokenizer\":\"some-tokenizer\"}");
124+
}
125+
105126
@Test
106127
public void testBuilders() {
107128
String json = "{\"exists\":{\"field\":\"foo\"}}";

0 commit comments

Comments
 (0)