Created
April 25, 2012 16:18
-
-
Save kimchy/2491022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.elasticsearch.action.count.CountResponse; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.settings.Settings; | |
import org.elasticsearch.node.Node; | |
import org.elasticsearch.node.NodeBuilder; | |
/** | |
*/ | |
public class Test { | |
public static void main(String[] args) throws InterruptedException { | |
Settings settings = ImmutableSettings.settingsBuilder() | |
.put("node.data", false) | |
.put("node.local", false) | |
.put("node.master", false) | |
.put("network.host", "127.0.0.1") | |
.put("discovery.type", "zen") | |
.put("discovery.zen.minimum_master_nodes", 1) | |
.put("discovery.zen.ping.multicast.enabled", false) | |
.putArray("discovery.zen.ping.unicast.hosts", "127.0.0.1") | |
.build(); | |
Node node = NodeBuilder.nodeBuilder().settings(settings).node(); | |
// clean all indices | |
node.client().admin().indices().prepareDelete().execute().actionGet(); | |
// create the test index | |
node.client().admin().indices().prepareCreate("test").execute().actionGet(); | |
// index sample doc | |
node.client().prepareIndex("test", "type", "1").setSource("field", "value").execute().actionGet(); | |
while (true) { | |
Thread.sleep(5000); | |
try { | |
System.out.println("Executing count"); | |
CountResponse countResponse = node.client().prepareCount("test").execute().actionGet(); | |
System.out.println("Got " + countResponse.count()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment