Skip to content

Commit

Permalink
Add default variant to Analyzer (#522) (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
swallez committed Mar 6, 2023
1 parent c7117b4 commit 0b9456d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ protected static void setupAnalyzerDeserializer(ObjectDeserializer<Builder> op)
builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper));
});

op.setTypeProperty("type", null);
op.setTypeProperty("type", "custom");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package co.elastic.clients.elasticsearch.model;

import co.elastic.clients.elasticsearch._types.analysis.Analyzer;
import co.elastic.clients.elasticsearch._types.mapping.Property;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
import co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore;
Expand All @@ -29,6 +30,8 @@
import co.elastic.clients.json.JsonData;
import org.junit.jupiter.api.Test;

import java.util.function.Consumer;

public class VariantsTest extends ModelTestCase {

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

@Test
public void testDefaultInternalTag() {

Consumer<String> test = s -> {
Analyzer a = fromJson(s, Analyzer.class);
assertEquals(Analyzer.Kind.Custom, a._kind());
assertEquals("some-filter", a.custom().filter().get(0));
assertTrue(a.custom().charFilter().isEmpty());
assertEquals("some-tokenizer", a.custom().tokenizer());
};

// Explicit type
test.accept("{\"type\":\"custom\",\"filter\":[\"some-filter\"],\"tokenizer\":\"some-tokenizer\"}");

// Default type
test.accept("{\"filter\":[\"some-filter\"],\"tokenizer\":\"some-tokenizer\"}");
}

@Test
public void testBuilders() {
String json = "{\"exists\":{\"field\":\"foo\"}}";
Expand Down

0 comments on commit 0b9456d

Please sign in to comment.