Skip to content

Instantly share code, notes, and snippets.

@phillro
Created August 5, 2011 02:33
Show Gist options
  • Save phillro/1126819 to your computer and use it in GitHub Desktop.
Save phillro/1126819 to your computer and use it in GitHub Desktop.
Grails Restclient. Elastic Search with authentication for ElasticSearch HQ
withRest(uri: 'https://esh01.elasticsearchhq.com:9200) {
handler.success = { resp, results ->
return results
}
handler.failure = { resp ->
log.error "Unexpected failure: ${resp.statusLine}"
return false;
}
def response = post(
path: indexname + '/_search',
body: queryObj,
headers: ['Authorization': "Basic " + this.encodeAuth(username, password) + "=="],
requestContentType: JSON
)
}
public String encodeAuth(username, password) {
def authC = username + ':' + password
def bytes = authC.bytes
return bytes.encodeBase64().toString();
}
@pvsousalima
Copy link

Nice gist! Where in the grails project should I put this code? I have an ElasticSearch instance running aside from my Grails project. I want make my grails app be the only one to be ale to athenticate and get info (search, index) from my ElasticSearch. Any clue? Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment