GetMapping failed when index had no mapping (yet)

Closes #3534
This commit is contained in:
Boaz Leskes 2013-08-19 15:51:10 +02:00
parent 103059d9ef
commit cd5ebac7dd
2 changed files with 28 additions and 19 deletions

View File

@ -236,9 +236,8 @@ public class MetaData implements Iterable<IndexMetaData> {
* Finds the specific index aliases that match with the specified aliases directly or partially via wildcards and * Finds the specific index aliases that match with the specified aliases directly or partially via wildcards and
* that point to the specified concrete indices or match partially with the indices via wildcards. * that point to the specified concrete indices or match partially with the indices via wildcards.
* *
* @param aliases The names of the index aliases to find * @param aliases The names of the index aliases to find
* @param concreteIndices The concrete indexes the index aliases must point to order to be returned. * @param concreteIndices The concrete indexes the index aliases must point to order to be returned.
*
* @return the found index aliases grouped by index * @return the found index aliases grouped by index
*/ */
public ImmutableMap<String, ImmutableList<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) { public ImmutableMap<String, ImmutableList<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) {
@ -255,8 +254,8 @@ public class MetaData implements Iterable<IndexMetaData> {
Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() { Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() {
public boolean apply(String alias) { public boolean apply(String alias) {
// Simon says: we could build and FST out of the alias key and then run a regexp query against it ;) // Simon says: we could build and FST out of the alias key and then run a regexp query against it ;)
return Regex.simpleMatch(aliases, alias); return Regex.simpleMatch(aliases, alias);
} }
}).values(); }).values();
@ -271,9 +270,8 @@ public class MetaData implements Iterable<IndexMetaData> {
* Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the * Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the
* alias names for partial matches. * alias names for partial matches.
* *
* @param aliases The names of the index aliases to find * @param aliases The names of the index aliases to find
* @param concreteIndices The concrete indexes the index aliases must point to order to be returned. * @param concreteIndices The concrete indexes the index aliases must point to order to be returned.
*
* @return whether at least one of the specified aliases exists in one of the specified concrete indices. * @return whether at least one of the specified aliases exists in one of the specified concrete indices.
*/ */
public boolean hasAliases(final String[] aliases, String[] concreteIndices) { public boolean hasAliases(final String[] aliases, String[] concreteIndices) {
@ -289,7 +287,7 @@ public class MetaData implements Iterable<IndexMetaData> {
Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() { Collection<AliasMetaData> filteredValues = Maps.filterKeys(indexMetaData.getAliases(), new Predicate<String>() {
public boolean apply(String alias) { public boolean apply(String alias) {
return Regex.simpleMatch(aliases, alias); return Regex.simpleMatch(aliases, alias);
} }
}).values(); }).values();
@ -313,7 +311,8 @@ public class MetaData implements Iterable<IndexMetaData> {
IndexMetaData indexMetaData = indices.get(index); IndexMetaData indexMetaData = indices.get(index);
Map<String, MappingMetaData> filteredMappings; Map<String, MappingMetaData> filteredMappings;
if (types.length == 0) { if (types.length == 0) {
filteredMappings = indexMetaData.getMappings(); // No types specified means get it all indexMapBuilder.put(index, ImmutableMap.copyOf(indexMetaData.getMappings())); // No types specified means get it all
} else { } else {
filteredMappings = Maps.filterKeys(indexMetaData.getMappings(), new Predicate<String>() { filteredMappings = Maps.filterKeys(indexMetaData.getMappings(), new Predicate<String>() {
@ -323,9 +322,9 @@ public class MetaData implements Iterable<IndexMetaData> {
} }
}); });
} if (!filteredMappings.isEmpty()) {
if (!filteredMappings.isEmpty()) { indexMapBuilder.put(index, ImmutableMap.copyOf(filteredMappings));
indexMapBuilder.put(index, ImmutableMap.copyOf(filteredMappings)); }
} }
} }
return indexMapBuilder.build(); return indexMapBuilder.build();
@ -633,9 +632,9 @@ public class MetaData implements Iterable<IndexMetaData> {
} }
} }
} }
if (actualIndices.isEmpty()) { if (actualIndices.isEmpty()) {
throw new IndexMissingException(new Index(Arrays.toString(aliasesOrIndices))); throw new IndexMissingException(new Index(Arrays.toString(aliasesOrIndices)));
} }
return actualIndices.toArray(new String[actualIndices.size()]); return actualIndices.toArray(new String[actualIndices.size()]);
} }
@ -868,7 +867,7 @@ public class MetaData implements Iterable<IndexMetaData> {
* Identifies whether the first argument (an array containing index names) is a pattern that matches all indices * Identifies whether the first argument (an array containing index names) is a pattern that matches all indices
* *
* @param indicesOrAliases the array containing index names * @param indicesOrAliases the array containing index names
* @param concreteIndices array containing the concrete indices that the first argument refers to * @param concreteIndices array containing the concrete indices that the first argument refers to
* @return true if the first argument is a pattern that maps to all available indices, false otherwise * @return true if the first argument is a pattern that maps to all available indices, false otherwise
*/ */
public boolean isPatternMatchingAllIndices(String[] indicesOrAliases, String[] concreteIndices) { public boolean isPatternMatchingAllIndices(String[] indicesOrAliases, String[] concreteIndices) {
@ -897,8 +896,12 @@ public class MetaData implements Iterable<IndexMetaData> {
} }
public static boolean isGlobalStateEquals(MetaData metaData1, MetaData metaData2) { public static boolean isGlobalStateEquals(MetaData metaData1, MetaData metaData2) {
if (!metaData1.persistentSettings.equals(metaData2.persistentSettings)) return false; if (!metaData1.persistentSettings.equals(metaData2.persistentSettings)) {
if (!metaData1.templates.equals(metaData2.templates())) return false; return false;
}
if (!metaData1.templates.equals(metaData2.templates())) {
return false;
}
return true; return true;
} }

View File

@ -27,15 +27,21 @@ import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/** /**
* *
*/ */
public class SimpleGetMappingsTests extends AbstractSharedClusterTest { public class SimpleGetMappingsTests extends AbstractSharedClusterTest {
@Test
public void getMappingsWhereThereAreNone() {
createIndex("index");
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
assertThat(response.mappings(), hasKey("index"));
assertThat(response.mappings().get("index").size(), equalTo(0));
}
@Test @Test
public void simpleGetMappings() throws Exception { public void simpleGetMappings() throws Exception {
XContentBuilder mapping = jsonBuilder().startObject().startObject("properties") XContentBuilder mapping = jsonBuilder().startObject().startObject("properties")