32
32
import org .junit .jupiter .api .Test ;
33
33
import org .springframework .core .annotation .AliasFor ;
34
34
import org .springframework .data .annotation .Id ;
35
+ import org .springframework .data .elasticsearch .core .completion .Completion ;
35
36
import org .springframework .data .elasticsearch .core .convert .MappingElasticsearchConverter ;
36
37
import org .springframework .data .elasticsearch .core .index .MappingBuilder ;
37
38
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentProperty ;
@@ -73,12 +74,17 @@ void fieldAnnotationShouldBeComposable() {
73
74
assertThat (property .storeNullValue ()).isTrue ();
74
75
}
75
76
76
- @ Test // DATAES-362
77
+ @ Test // DATAES-362, #1836
77
78
@ DisplayName ("should use composed Field annotations in MappingBuilder" )
78
79
void shouldUseComposedFieldAnnotationsInMappingBuilder () throws JSONException {
79
80
80
81
String expected = "{\n " + //
81
- " \" properties\" :{\n " + //
82
+ " \" properties\" : {\n " + //
83
+ " \" _class\" : {\n " + //
84
+ " \" type\" : \" keyword\" ,\n " + //
85
+ " \" index\" : false,\n " + //
86
+ " \" doc_values\" : false\n " + //
87
+ " },\n " + //
82
88
" \" null-value\" : {\n " + //
83
89
" \" null_value\" : \" NULL\" \n " + //
84
90
" },\n " + //
@@ -93,13 +99,21 @@ void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
93
99
" \" type\" : \" keyword\" \n " + //
94
100
" }\n " + //
95
101
" }\n " + //
102
+ " },\n " + //
103
+ " \" suggest\" : {\n " + //
104
+ " \" type\" : \" completion\" ,\n " + //
105
+ " \" max_input_length\" : 50,\n " + //
106
+ " \" preserve_position_increments\" : true,\n " + //
107
+ " \" preserve_separators\" : true,\n " + //
108
+ " \" search_analyzer\" : \" myAnalyzer\" ,\n " + //
109
+ " \" analyzer\" : \" myAnalyzer\" \n " + //
96
110
" }\n " + //
97
111
" }\n " + //
98
112
"}\n " ; //
99
113
100
114
String mapping = mappingBuilder .buildPropertyMapping (ComposedAnnotationEntity .class );
101
115
102
- assertEquals (expected , mapping , false );
116
+ assertEquals (expected , mapping , true );
103
117
}
104
118
105
119
@ Inherited
@@ -142,12 +156,21 @@ void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
142
156
public @interface TextKeywordField {
143
157
}
144
158
159
+ @ Inherited
160
+ @ Documented
161
+ @ Retention (RetentionPolicy .RUNTIME )
162
+ @ Target (ElementType .FIELD )
163
+ @ CompletionField (analyzer = "myAnalyzer" , searchAnalyzer = "myAnalyzer" )
164
+ public @interface MyAnalyzerCompletionField {
165
+ }
166
+
145
167
@ DocumentNoCreate (indexName = "test-no-create" )
146
168
static class ComposedAnnotationEntity {
147
169
@ Nullable @ Id private String id ;
148
170
@ Nullable @ NullValueField (name = "null-value" ) private String nullValue ;
149
171
@ Nullable @ LocalDateField private LocalDate theDate ;
150
172
@ Nullable @ TextKeywordField private String multiField ;
173
+ @ Nullable @ MyAnalyzerCompletionField private Completion suggest ;
151
174
152
175
@ Nullable
153
176
public String getId () {
@@ -184,5 +207,14 @@ public String getMultiField() {
184
207
public void setMultiField (@ Nullable String multiField ) {
185
208
this .multiField = multiField ;
186
209
}
210
+
211
+ @ Nullable
212
+ public Completion getSuggest () {
213
+ return suggest ;
214
+ }
215
+
216
+ public void setSuggest (@ Nullable Completion suggest ) {
217
+ this .suggest = suggest ;
218
+ }
187
219
}
188
220
}
0 commit comments