Skip to content

Instantly share code, notes, and snippets.

@alemures
Created November 30, 2016 17:13
Show Gist options
  • Save alemures/caafcf1113c9107b1d2b32ecc49509e2 to your computer and use it in GitHub Desktop.
Save alemures/caafcf1113c9107b1d2b32ecc49509e2 to your computer and use it in GitHub Desktop.
Elasticsearch response as string with Node.js client library
// Working with elasticsearch client 12.1.0
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: '127.0.0.1:9200',
log: 'warning'
});
// Override per default deserialize method without JSON.parse()
client.transport.serializer.deserialize = function (str) {
if (typeof str === 'string') {
return str;
}
};
client.search(
{
index: 'index',
type: 'type',
body: {
query: {
match_all: {}
}
}
}, function (err, response) {
console.log(err || response);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment