I am trying to connect to ElasticSearch through Angular following an example provided, but I keep getting a 404 not found error:
{"msg":"Not Found","path":"/myindex/_search",
"query":{"q":"something"},"statusCode":404,"response":""}
I was able to ping the ElasticSearch server successfully using the es ping API.
The code I am using is as follows:
var EsConnector = angular.module('EsConnector', ['elasticsearch']);
// Create the es service from the esFactory
EsConnector.service('es', function (esFactory) {
return esFactory({
host: 'localhost:9200',
log: 'trace' });
});
EsConnector.controller('ShortQueryController', function( $scope, es ) {
$scope.responseStatus = '';
$scope.responseText = '';
// search for documents
es.search( {
index: 'myindex',
q: 'something'
} ).then( function ( error, response ) {
if ( error ) {
$scope.data = error.message;
} else {
$scope.hits = response.hits.hits;
$scope.responseStatus = response.status;
$scope.responseText = response.statusText;
}
} ).catch( function(response) {
$scope.responseStatus = response.status;
$scope.responseText = JSON.stringify( response );
} );
});
The 404 is trapped in the catch block. Also, I tried using the authentication string user:pwd and https settings when creating the service, but it made no difference.
Additionally, I have verified that there is valid data at localhost:9200/myindex with a direct browser call and through Kibana which was able to connect.
The index and other syntax has been masked/redacted with notional names in the above example. i.e. the index is not actually "myindex".
The example that I formulated is a combination of the following two references:
ElasticSearch.js Example and
ElasticSearch-Angular Example
What is causing the 404 not found error?