Skip to content

Instantly share code, notes, and snippets.

Created November 27, 2011 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1398083 to your computer and use it in GitHub Desktop.
Save anonymous/1398083 to your computer and use it in GitHub Desktop.
JUnit test connecting to local ES node
public class EsNodeLocalTest {
@Test
public void testLocalEs() throws IOException, InterruptedException {
Settings esSettings = ImmutableSettings.settingsBuilder()
.put("path.data", pathData)
.put("id", "a23")
.build();
NodeBuilder nBuilder = nodeBuilder().settings(esSettings);
nBuilder.local(true);
final Node node = nBuilder.build().start();
Thread.sleep(3*1000);
Client esClient = new TransportClient().addTransportAddress(new LocalTransportAddress("a23"));
SearchRequestBuilder impl = esClient.prepareSearch("xxxindex");
impl.setSearchType(SearchType.QUERY_THEN_FETCH);
impl.setTypes("xxxtype");
impl.setFrom(1);
impl.setSize(5);
SearchResponse res = impl.execute().actionGet();
LOG.info(res);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment