Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

/CallingCode Secret

Created July 27, 2016 09:46
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/7ccd596a571284af7ef20bd66789c77b to your computer and use it in GitHub Desktop.
Save anonymous/7ccd596a571284af7ef20bd66789c77b to your computer and use it in GitHub Desktop.
public SearchResponse doSearchSecure(String field, String value) throws UnknownHostException{
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "es_cluster").build();
Client client = TransportClient.builder()
.settings(settings).addPlugin(SecureRestSearchActionPlugin.class)
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
boolean indexExists = client.admin().indices().prepareExists("my_index").execute().actionGet().isExists();
if(!indexExists) return null;
SecureSearchAction action = SecureSearchAction.INSTANCE;
SearchRequestBuilder srb = client.prepareExecute(action).
setIndices(INDEX).addFields("Field1","Field2")
.setQuery(QueryBuilders.matchAllQuery()).setTypes("my_type");
SearchRequest sR = srb.request();
ActionFuture<SearchResponse> respAction = client.execute(action, sR);
SearchResponse allHits = respAction.actionGet();
System.out.println(allHits.toString());
return allHits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment