Skip to content

Instantly share code, notes, and snippets.

@kimchy
Created April 25, 2012 16:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimchy/2491022 to your computer and use it in GitHub Desktop.
Save kimchy/2491022 to your computer and use it in GitHub Desktop.
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