Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import java.lang.annotation.Target;

/**
* Based on the reference doc - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
* Based on the reference doc -
* https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
*
* @author Mewes Kochheim
* @author Robert Gruendler
* @author Peter-Josef Meisch
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
@Documented
@Inherited
public @interface CompletionField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.core.completion.Completion;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
Expand Down Expand Up @@ -73,12 +74,17 @@ void fieldAnnotationShouldBeComposable() {
assertThat(property.storeNullValue()).isTrue();
}

@Test // DATAES-362
@Test // DATAES-362, #1836
@DisplayName("should use composed Field annotations in MappingBuilder")
void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {

String expected = "{\n" + //
" \"properties\":{\n" + //
" \"properties\": {\n" + //
" \"_class\": {\n" + //
" \"type\": \"keyword\",\n" + //
" \"index\": false,\n" + //
" \"doc_values\": false\n" + //
" },\n" + //
" \"null-value\": {\n" + //
" \"null_value\": \"NULL\"\n" + //
" },\n" + //
Expand All @@ -93,13 +99,21 @@ void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
" \"type\": \"keyword\"\n" + //
" }\n" + //
" }\n" + //
" },\n" + //
" \"suggest\": {\n" + //
" \"type\": \"completion\",\n" + //
" \"max_input_length\": 50,\n" + //
" \"preserve_position_increments\": true,\n" + //
" \"preserve_separators\": true,\n" + //
" \"search_analyzer\": \"myAnalyzer\",\n" + //
" \"analyzer\": \"myAnalyzer\"\n" + //
" }\n" + //
" }\n" + //
"}\n"; //

String mapping = mappingBuilder.buildPropertyMapping(ComposedAnnotationEntity.class);

assertEquals(expected, mapping, false);
assertEquals(expected, mapping, true);
}

@Inherited
Expand Down Expand Up @@ -142,12 +156,21 @@ void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
public @interface TextKeywordField {
}

@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@CompletionField(analyzer = "myAnalyzer", searchAnalyzer = "myAnalyzer")
public @interface MyAnalyzerCompletionField {
}

@DocumentNoCreate(indexName = "test-no-create")
static class ComposedAnnotationEntity {
@Nullable @Id private String id;
@Nullable @NullValueField(name = "null-value") private String nullValue;
@Nullable @LocalDateField private LocalDate theDate;
@Nullable @TextKeywordField private String multiField;
@Nullable @MyAnalyzerCompletionField private Completion suggest;

@Nullable
public String getId() {
Expand Down Expand Up @@ -184,5 +207,14 @@ public String getMultiField() {
public void setMultiField(@Nullable String multiField) {
this.multiField = multiField;
}

@Nullable
public Completion getSuggest() {
return suggest;
}

public void setSuggest(@Nullable Completion suggest) {
this.suggest = suggest;
}
}
}