Skip to content

Instantly share code, notes, and snippets.

@colinpollock
Created June 26, 2013 20:38
Show Gist options
  • Save colinpollock/5871423 to your computer and use it in GitHub Desktop.
Save colinpollock/5871423 to your computer and use it in GitHub Desktop.
JestClient search authentication
public static ClientConfig getClientConfig(String connectionUrl) {
ClientConfig clientConfig = new ClientConfig();
LinkedHashSet<String> servers = new LinkedHashSet<String>();
servers.add(connectionUrl);
clientConfig.getServerProperties().put(ClientConstants.SERVER_LIST, servers);
return clientConfig;
}
public static JestClient getClient(String connectionUrl) {
JestClientFactory factory = new JestClientFactory();
factory.setClientConfig(getClientConfig(connectionUrl));
return factory.getObject();
}
QueryBuilder queryBuilder = QueryBuilders.termQuery("field", value);
Search search = new Search(Search.createQueryWithBuilder(queryBuilder.toString()));
search.addIndex(INDEX);
search.addType(TYPE);
getClientConfig(URL).execute(search);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment