Skip to content

Commit

Permalink
#70 Fix ES Delete index when having a template
Browse files Browse the repository at this point in the history
Fix the delete index issue and add a unit test.
  • Loading branch information
vroyer committed Dec 29, 2016
1 parent 03323d5 commit aba0095
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.threadpool.ThreadPool;

import com.carrotsearch.hppc.cursors.ObjectCursor;
Expand Down Expand Up @@ -100,7 +101,8 @@ public ClusterState execute(final ClusterState currentState) throws Exception {
final IndexMetaData indexMetaData = currentState.metaData().index(index);
// record keyspace.table having useless 2i
for(ObjectCursor<MappingMetaData> type:indexMetaData.getMappings().values())
unindexedTables.put(indexMetaData, InternalCassandraClusterService.typeToCfName(type.value.type()));
if (!MapperService.DEFAULT_MAPPING.equals(type.value.type()))
unindexedTables.put(indexMetaData, InternalCassandraClusterService.typeToCfName(type.value.type()));
}

MetaData newMetaData = metaDataBuilder.build();
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/org/elassandra/NamedUdtTests.java
Expand Up @@ -49,4 +49,23 @@ public void testNamedUDT() throws Exception {
assertThat(results.size(),equalTo(1));
}

@Test
public void testIndexNameTranslation() throws Exception {
assertThat(client().admin().indices().preparePutTemplate("test_template")
.addMapping("_default_", "{ \"_default_\": { \"properties\": { \"attachment\": { \"type\": \"binary\" }}}}")
.setTemplate("test_index-*")
.get().isAcknowledged(), equalTo(true));

assertThat(client().prepareIndex("test_index-2016.12.29", "tweet-info", "1")
.setSource("{ \"user\": { \"user_id\": \"500\", \"user_email\":\"user@test.com\" }, \"message\": \"hello\" }")
.get().isCreated(), equalTo(true));
ensureGreen("test_index-2016.12.29");

assertThat(client().prepareGet().setIndex("test_index-2016.12.29").setType("tweet-info").setId("1").get().isExists(), equalTo(true));
assertThat(client().prepareMultiGet().add("test_index-2016.12.29","tweet-info","1").get().getResponses().length, equalTo(1));
assertThat(client().prepareSearch("test_index-2016.12.29").setTypes("tweet-info").setQuery(QueryBuilders.queryStringQuery("message:hello")).get().getHits().getTotalHits(), equalTo(1L));
assertThat(client().prepareDelete().setIndex("test_index-2016.12.29").setType("tweet-info").setId("1").get().getId(), equalTo("1"));
assertThat(client().admin().indices().prepareDelete("test_index-2016.12.29").get().isAcknowledged(), equalTo(true));
assertThat(client().admin().indices().prepareDeleteTemplate("test_template").get().isAcknowledged(), equalTo(true));
}
}

0 comments on commit aba0095

Please sign in to comment.