Skip to content

Commit

Permalink
delete by query is now a plugin
Browse files Browse the repository at this point in the history
https://www.elastic.co/guide/en/elasticsearch/plugins/2.0/plugins-delete-by-query.html

solving jar hell with junit, mockito and hamcrest.

upgrading to es2, rc1.
  • Loading branch information
andrejserafim committed Oct 17, 2015
1 parent e221a14 commit 959b054
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
7 changes: 6 additions & 1 deletion jest-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -97,7 +102,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion jest-droid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
6 changes: 5 additions & 1 deletion jest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>delete-by-query</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugin.deletebyquery.DeleteByQueryPlugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -33,6 +34,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
.put(Node.HTTP_ENABLED, true)
.put("plugin.types", DeleteByQueryPlugin.class.getName())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package io.searchbox.core;

import com.google.common.base.Predicate;
import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.plugin.deletebyquery.DeleteByQueryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

/**
* @author Dogukan Sonmez
Expand All @@ -14,25 +21,52 @@
public class DeleteByQueryIntegrationTest extends AbstractIntegrationTest {

@Test
public void delete() throws IOException {
String query = "{\n" +
" \"query\" : {\n" +
" \"term\" : { \"user\" : \"kimchy\" }\n" +
public void delete() throws IOException, InterruptedException {
final String query = "{\n" +
" \"query\": {\n" +
" \"term\": { \"user\" : \"kimchy\" }\n" +
" }\n" +
"}";
client.execute(new Index.Builder("\"user\":\"kimchy\"").index("twitter").type("tweet").id("1").build());
client.execute(new Index.Builder("{\"user\":\"kimchy\"}").index("twitter").type("tweet").id("1").build());

waitForDocumentToBeIndexed(query);

Thread.sleep(1000);

DeleteByQuery deleteByQuery = new DeleteByQuery.Builder(query)
.addIndex("twitter")
.addType("tweet")
.build();

JestResult result = client.execute(deleteByQuery);
assertTrue(result.getErrorMessage(), result.isSucceeded());;
assertTrue(result.getErrorMessage(), result.isSucceeded());

assertEquals(
0,
result.getJsonObject().getAsJsonObject("_indices").getAsJsonObject("twitter").getAsJsonObject("_shards").get("failed").getAsInt()
result.getJsonObject().getAsJsonObject("_indices").getAsJsonObject("twitter").get("failed").getAsInt()
);
assertEquals(
1,
result.getJsonObject().getAsJsonObject("_indices").getAsJsonObject("twitter").get("deleted").getAsInt()
);
}

private void waitForDocumentToBeIndexed(final String query) throws InterruptedException {
awaitBusy(new Predicate<Object>() {
@Override
public boolean apply(Object input) {
try {
SearchResult searchResult = client.execute(new Search.Builder(query)
.addIndex("twitter")
.addType("tweet")
.build());
System.out.println(searchResult.getJsonString());
return null != searchResult.getFirstHit(Map.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}

}
23 changes: 21 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<elasticsearch.version>2.0.0-beta1</elasticsearch.version>
<elasticsearch.version>2.0.0-rc1</elasticsearch.version>

<lucene.version>5.2.1</lucene.version>
<hamcrest.version>1.3</hamcrest.version>
Expand Down Expand Up @@ -155,6 +155,7 @@
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
<check/>
</configuration>
</plugin>

Expand Down Expand Up @@ -254,6 +255,12 @@
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -269,12 +276,24 @@
<version>${elasticsearch.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>delete-by-query</artifactId>
<version>${elasticsearch.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down

0 comments on commit 959b054

Please sign in to comment.