Created
August 5, 2011 02:33
-
-
Save phillro/1126819 to your computer and use it in GitHub Desktop.
Grails Restclient. Elastic Search with authentication for ElasticSearch HQ
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
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)