-
-
Save anonymous/7ccd596a571284af7ef20bd66789c77b to your computer and use it in GitHub Desktop.
This file contains 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
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