Skip to content

Commit 0dfacef

Browse files
committed
Added test with awaits annotation that exposes a merge mapping issue.
If the path_type is set to `just_name` in a multi_field typed field and that field is updated (for example another multi field is added) then if the path isn't specified again the path_type isn't taken into account and full path names are generated.
1 parent ebb9884 commit 0dfacef

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
2222
import com.google.common.collect.Lists;
23+
import org.apache.lucene.util.LuceneTestCase;
2324
import org.elasticsearch.ExceptionsHelper;
2425
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
2526
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
@@ -28,10 +29,8 @@
2829
import org.elasticsearch.action.admin.indices.segments.ShardSegments;
2930
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
3031
import org.elasticsearch.action.index.IndexRequestBuilder;
31-
import org.elasticsearch.action.percolate.PercolateResponse;
3232
import org.elasticsearch.action.search.SearchPhaseExecutionException;
3333
import org.elasticsearch.action.suggest.SuggestResponse;
34-
import org.elasticsearch.client.Requests;
3534
import org.elasticsearch.common.settings.ImmutableSettings;
3635
import org.elasticsearch.common.settings.Settings;
3736
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -58,7 +57,6 @@
5857
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
5958
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
6059
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
61-
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
6260
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
6361
import static org.hamcrest.Matchers.*;
6462

@@ -428,6 +426,58 @@ public void testThatUpgradeToMultiFieldWorks() throws Exception {
428426
assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters");
429427
}
430428

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+
431481
@Test
432482
public void testThatFuzzySuggesterWorks() throws Exception {
433483
createIndexAndMapping(completionMappingBuilder);

0 commit comments

Comments
 (0)