# Angular to ElasticSearch Returning 404 Not Found

**URL:** <https://discuss.elastic.co/t/angular-to-elasticsearch-returning-404-not-found/126746>\
**Category:** Elasticsearch\
**Created:** [April 4, 2018, 1:31pm UTC](https://discuss.elastic.co/t/angular-to-elasticsearch-returning-404-not-found/126746 "2018-04-04T13:31:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisruel](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@chrisruel](https://discuss.elastic.co/u/chrisruel)\
**Post date:** [April 4, 2018, 1:31pm UTC](https://discuss.elastic.co/t/angular-to-elasticsearch-returning-404-not-found/126746/1 "2018-04-04T13:31:00Z")

</div>

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](https://github.com/elastic/elasticsearch-js) and  
[ElasticSearch-Angular Example](https://github.com/spalger/elasticsearch-angular-example)

What is causing the 404 not found error?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 2, 2018, 1:31pm UTC](https://discuss.elastic.co/t/angular-to-elasticsearch-returning-404-not-found/126746/2 "2018-05-02T13:31:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
