|
71 | 71 | import static java.util.Arrays.asList; |
72 | 72 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasProperty; |
73 | 73 | import static org.hamcrest.Matchers.containsInAnyOrder; |
| 74 | +import static org.hamcrest.Matchers.containsString; |
74 | 75 | import static org.hamcrest.Matchers.equalTo; |
75 | 76 | import static org.hamcrest.Matchers.hasSize; |
76 | 77 | import static org.hamcrest.Matchers.notNullValue; |
@@ -180,6 +181,60 @@ public void testConfiguration() throws IOException { |
180 | 181 | getShingleFieldMapper(defaultMapper, "a_field._4gram").fieldType(), 4, analyzerName, prefixFieldMapper.fieldType()); |
181 | 182 | } |
182 | 183 |
|
| 184 | + public void testSimpleMerge() throws IOException { |
| 185 | + MapperService mapperService = createIndex("test").mapperService(); |
| 186 | + { |
| 187 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() |
| 188 | + .startObject("_doc") |
| 189 | + .startObject("properties") |
| 190 | + .startObject("a_field") |
| 191 | + .field("type", "search_as_you_type") |
| 192 | + .field("analyzer", "standard") |
| 193 | + .endObject() |
| 194 | + .endObject() |
| 195 | + .endObject().endObject()); |
| 196 | + DocumentMapper mapper = mapperService.merge("_doc", |
| 197 | + new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); |
| 198 | + } |
| 199 | + |
| 200 | + { |
| 201 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() |
| 202 | + .startObject("_doc") |
| 203 | + .startObject("properties") |
| 204 | + .startObject("a_field") |
| 205 | + .field("type", "search_as_you_type") |
| 206 | + .field("analyzer", "standard") |
| 207 | + .endObject() |
| 208 | + .startObject("b_field") |
| 209 | + .field("type", "text") |
| 210 | + .endObject() |
| 211 | + .endObject() |
| 212 | + .endObject().endObject()); |
| 213 | + DocumentMapper mapper = mapperService.merge("_doc", |
| 214 | + new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE); |
| 215 | + } |
| 216 | + |
| 217 | + { |
| 218 | + String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject() |
| 219 | + .startObject("_doc") |
| 220 | + .startObject("properties") |
| 221 | + .startObject("a_field") |
| 222 | + .field("type", "search_as_you_type") |
| 223 | + .field("analyzer", "standard") |
| 224 | + .field("max_shingle_size", "4") |
| 225 | + .endObject() |
| 226 | + .startObject("b_field") |
| 227 | + .field("type", "text") |
| 228 | + .endObject() |
| 229 | + .endObject() |
| 230 | + .endObject().endObject()); |
| 231 | + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, |
| 232 | + () -> mapperService.merge("_doc", |
| 233 | + new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE)); |
| 234 | + assertThat(e.getMessage(), containsString("different [max_shingle_size]")); |
| 235 | + } |
| 236 | + } |
| 237 | + |
183 | 238 | public void testIndexOptions() throws IOException { |
184 | 239 | final String mapping = Strings.toString(XContentFactory.jsonBuilder() |
185 | 240 | .startObject() |
|
0 commit comments