Skip to content

Commit

Permalink
Improve detection of index existence
Browse files Browse the repository at this point in the history
Allow aliases (like _all) to be used only when reading data.

fix #205
fix #233

(cherry picked from commit 7527c4a)
  • Loading branch information
costin committed Aug 13, 2014
1 parent ee72401 commit 34c7bee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -274,7 +274,14 @@ public List<Object[]> scroll(String scrollId, ScrollReader reader) throws IOExce

public boolean indexExists(boolean read) throws IOException {
Resource res = (read ? resourceR : resourceW);
return client.exists(res.indexAndType());
// cheap hit
boolean exists = client.exists(res.indexAndType());
// could be a _all or a pattern which is valid for read
// try again by asking the mapping - could be expensive
if (!exists && read) {
exists = !client.getMapping(res.mapping()).isEmpty();
}
return exists;
}

public void putMapping(BytesArray mapping) throws IOException {
Expand Down
12 changes: 12 additions & 0 deletions mr/src/test/java/org/elasticsearch/hadoop/rest/ResourceTest.java
Expand Up @@ -29,6 +29,18 @@

public class ResourceTest {

@Test
public void testJustIndex() throws Exception {
Resource res = createResource("foo/_all");
assertEquals("foo/_all", res.indexAndType());
}

@Test
public void testJustType() throws Exception {
Resource res = createResource("_all/foo");
assertEquals("_all/foo", res.indexAndType());
}

@Test
public void testIndexAndType() throws Exception {
Resource res = createResource("foo/bar");
Expand Down

0 comments on commit 34c7bee

Please sign in to comment.