|
20 | 20 |
|
21 | 21 | import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
22 | 22 | import com.google.common.collect.Lists;
|
| 23 | +import org.apache.lucene.util.LuceneTestCase; |
23 | 24 | import org.elasticsearch.ExceptionsHelper;
|
24 | 25 | import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
25 | 26 | import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
|
28 | 29 | import org.elasticsearch.action.admin.indices.segments.ShardSegments;
|
29 | 30 | import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
30 | 31 | import org.elasticsearch.action.index.IndexRequestBuilder;
|
31 |
| -import org.elasticsearch.action.percolate.PercolateResponse; |
32 | 32 | import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
33 | 33 | import org.elasticsearch.action.suggest.SuggestResponse;
|
34 |
| -import org.elasticsearch.client.Requests; |
35 | 34 | import org.elasticsearch.common.settings.ImmutableSettings;
|
36 | 35 | import org.elasticsearch.common.settings.Settings;
|
37 | 36 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
58 | 57 | import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
59 | 58 | import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
60 | 59 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
61 |
| -import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; |
62 | 60 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
63 | 61 | import static org.hamcrest.Matchers.*;
|
64 | 62 |
|
@@ -428,6 +426,58 @@ public void testThatUpgradeToMultiFieldWorks() throws Exception {
|
428 | 426 | assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters");
|
429 | 427 | }
|
430 | 428 |
|
| 429 | + @Test |
| 430 | + @LuceneTestCase.AwaitsFix(bugUrl = "path_type issue") |
| 431 | + // If the path_type is set to `just_name` and the multi field is updated (for example another multi field is added) |
| 432 | + // then if the path isn't specified again the path_type isn't taken into account and full path names are generated. |
| 433 | + public void testThatUpgradeToMultiFieldWorks_pathMergeIssue() throws Exception { |
| 434 | + Settings.Builder settingsBuilder = createDefaultSettings(); |
| 435 | + final XContentBuilder mapping = jsonBuilder() |
| 436 | + .startObject() |
| 437 | + .startObject(TYPE) |
| 438 | + .startObject("properties") |
| 439 | + .startObject(FIELD) |
| 440 | + .field("type", "multi_field") |
| 441 | + .field("path", "just_name") |
| 442 | + .startObject("fields") |
| 443 | + .startObject(FIELD).field("type", "string").endObject() |
| 444 | + .endObject() |
| 445 | + .endObject() |
| 446 | + .endObject() |
| 447 | + .endObject() |
| 448 | + .endObject(); |
| 449 | + client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).setSettings(settingsBuilder).get(); |
| 450 | + ensureYellow(); |
| 451 | + client().prepareIndex(INDEX, TYPE, "1").setRefresh(true).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get(); |
| 452 | + |
| 453 | + PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject() |
| 454 | + .startObject(TYPE).startObject("properties") |
| 455 | + .startObject(FIELD) |
| 456 | + .field("type", "multi_field") |
| 457 | + .startObject("fields") |
| 458 | + .startObject(FIELD).field("type", "string").endObject() |
| 459 | + .startObject("suggest").field("type", "completion").field("index_analyzer", "simple").field("search_analyzer", "simple").endObject() |
| 460 | + .endObject() |
| 461 | + .endObject() |
| 462 | + .endObject().endObject() |
| 463 | + .endObject()) |
| 464 | + .get(); |
| 465 | + assertThat(putMappingResponse.isAcknowledged(), is(true)); |
| 466 | + |
| 467 | + SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion( |
| 468 | + new CompletionSuggestionBuilder("suggs").field("suggest").text("f").size(10) |
| 469 | + ).execute().actionGet(); |
| 470 | + assertSuggestions(suggestResponse, "suggs"); |
| 471 | + |
| 472 | + client().prepareIndex(INDEX, TYPE, "1").setRefresh(true).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get(); |
| 473 | + waitForRelocation(ClusterHealthStatus.GREEN); |
| 474 | + |
| 475 | + SuggestResponse afterReindexingResponse = client().prepareSuggest(INDEX).addSuggestion( |
| 476 | + new CompletionSuggestionBuilder("suggs").field("suggest").text("f").size(10) |
| 477 | + ).execute().actionGet(); |
| 478 | + assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters"); |
| 479 | + } |
| 480 | + |
431 | 481 | @Test
|
432 | 482 | public void testThatFuzzySuggesterWorks() throws Exception {
|
433 | 483 | createIndexAndMapping(completionMappingBuilder);
|
|
0 commit comments