From 4754a83571c24a9843bef5cdf42c987c7cb60dd4 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 13 Jan 2014 16:29:13 +0100 Subject: [PATCH] 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. --- .../suggest/CompletionSuggestSearchTests.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java b/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java index 398ef99b89c..97f0e6e4788 100644 --- a/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java +++ b/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.suggest; import com.carrotsearch.randomizedtesting.generators.RandomStrings; import com.google.common.collect.Lists; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; @@ -483,6 +484,7 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest { .startObject(TYPE).startObject("properties") .startObject(FIELD) .field("type", "string") + .field("path", "just_name") // Need to specify path again, to make sure that the `path` is known when this mapping is parsed and turned into DocumentMapper that we merge with. .startObject("fields") .startObject("suggest").field("type", "completion").field("index_analyzer", "simple").field("search_analyzer", "simple").endObject() .endObject() @@ -506,6 +508,58 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest { assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters"); } + @Test + @LuceneTestCase.AwaitsFix(bugUrl = "path_type issue") + // If the path_type is set to `just_name` and the multi 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. + public void testThatUpgradeToMultiFieldWorks_bug() throws Exception { + Settings.Builder settingsBuilder = createDefaultSettings(); + final XContentBuilder mapping = jsonBuilder() + .startObject() + .startObject(TYPE) + .startObject("properties") + .startObject(FIELD) + .field("type", "multi_field") + .field("path", "just_name") + .startObject("fields") + .startObject(FIELD).field("type", "string").endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject(); + client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, mapping).setSettings(settingsBuilder).get(); + ensureYellow(); + client().prepareIndex(INDEX, TYPE, "1").setRefresh(true).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get(); + + PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject() + .startObject(TYPE).startObject("properties") + .startObject(FIELD) + .field("type", "multi_field") + .startObject("fields") + .startObject(FIELD).field("type", "string").endObject() + .startObject("suggest").field("type", "completion").field("index_analyzer", "simple").field("search_analyzer", "simple").endObject() + .endObject() + .endObject() + .endObject().endObject() + .endObject()) + .get(); + assertThat(putMappingResponse.isAcknowledged(), is(true)); + + SuggestResponse suggestResponse = client().prepareSuggest(INDEX).addSuggestion( + new CompletionSuggestionBuilder("suggs").field("suggest").text("f").size(10) + ).execute().actionGet(); + assertSuggestions(suggestResponse, "suggs"); + + client().prepareIndex(INDEX, TYPE, "1").setRefresh(true).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get(); + waitForRelocation(ClusterHealthStatus.GREEN); + + SuggestResponse afterReindexingResponse = client().prepareSuggest(INDEX).addSuggestion( + new CompletionSuggestionBuilder("suggs").field("suggest").text("f").size(10) + ).execute().actionGet(); + assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters"); + } + @Test public void testThatFuzzySuggesterWorks() throws Exception { createIndexAndMapping(completionMappingBuilder);