Cannot get the index information with GET method (404 not found)

Hi,

I followed this example to create my Kibana application. My use case is to display list of indices, select one and modify a specific line. As you see, this is the list of indices

Ths is my source code:
routes.js:

export default function (server) {

  let call = server.plugins.elasticsearch.callWithRequest;


  server.route({
    path: '/api/indices_view/_list',
    method: 'GET',
    handler(req, reply) {
      call(req, 'cluster.state').then(function (response) {
        // Return just the names of all indices to the client.
        reply(Object.keys(response.data.indices));
      });
    }
  });
  
  server.route({
    path: '/api/indices_view/index/{name}',
    method: 'GET',
    handler(req, reply) {
      call(req, 'cluster.state', {
        metric: 'metadata',
        index: req.params.name
      }).then(function (response) {
        //console.log("Route RES ======>", response);
        reply(response.metadata.indices[req.params.name]);
      });
    }
  });
}

app.js:

import { uiModules } from 'ui/modules';
import uiRoutes from 'ui/routes';
import 'angular-ui-bootstrap';
import 'ui/autoload/styles';
import './less/style.less';
import index from './templates/index.html';
import list from './templates/list.html';


uiRoutes.enable();

uiRoutes
.when('/', {
  template: index,
  controller: 'indicesView',
  controllerAs: 'ctrl'
})
.when('/index/:name', {
  template: list,
  controller: 'getIndiceByName',
  controllerAs: 'ctrl'
});

uiModules
.get('app/indices_view')
.controller('indicesView', function ($http) {
  $http.get('../api/indices_view/_list').then((response) => {
    this.indices = Object.keys(response.data.indices);
  });
})
.controller('getIndiceByName', function($routeParams, $http) {
  this.index = $routeParams.name;
  $http.get(`../api/indices_view/index/${this.index}`).then((response) => {
    this.status = response.data;
    console.log("App RES ======>", response);
  });
});

index.html:

<div class="container-fluid">
    <div class="row col-md-12 panel panel-default">         
        <div class="panel-body">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3">
                        <div id="imaginary_container"> 
                            <div class="input-group stylish-input-group">
                                <input type="text" class="form-control"  placeholder="Search" ng-model="indice">
                                <span class="input-group-addon">
                                    <button type="submit">
                                        <span class="glyphicon glyphicon-search"></span>
                                    </button>  
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-8 col-sm-offset-2">
                        <ul class="list-group">
                            <li class="list-group-item" ng-repeat="index in ctrl.indices | filter : indice"">
                              <a href="#/index/{{index}}">{{ index }}</a>
                            </li>  
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

I got this in my log: GET http://localhost:5601/api/indices_view/index/logstash-2015.05.20 404 (Not Found)

Did I miss something ? (This is the first time I use AngularJS)
I'll appreciate any help and thanks for advance :slight_smile:

Best regards !

Hmm, everything looks right, and since you're seeing the index list I'm assuming that the /api/indices_view/_list route is working fine. If you uncomment the console.log("Route RES ======>", response); line, does that should up in the console? If not then it's not even hitting that route, which is mysterious. Are you sure that the Kibana server has restarted and loaded your changes?

Thank you for your reply @spalger
Yes I uncomment all console.log and restart the server but I still have the same problem :frowning:

If you put a console log at the top of that file do you see it when the server start up?

Sorry I was restarting my PC (obligation).
I added the console log in the top of route.js and there is an error :

error [21:23:58.959] [warning][process] UnhandledPromiseRejectionWarning: TypeError: call is not a function
at handler (C:/Users/A701291/Desktop/ElasticStack/kibana-6.3.0/plugins/handle_app/server/routes.js:10:7)

eee

I remove the console log and restart the server, I still get this error. Any idea ? :zipper_mouth_face:

Are you using the development version of Kibana for this? It sounds like it's caching things that it shouldn't be because you're using the distributable version.

Did you use the Kibana plugin generator to get started? https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator

No, I am not using the dev version. I downloaded Kibana and Elasticsearch version 6.3 from here. Few minutes everything work perfectly!

I suggest starting fresh with the plugin generator, and then moving the code you have right now into the output from the generator. Then you'll be able to use yarn start to run your plugin, the server will automatically restart when you make changes, and things will be much more development friendly.

We don't really support developing plugins within the distributable

1 Like

Okay I'll do thanks @spalger :slight_smile:

Hello again @spalger, I followed you by starting with the plugin generator and using development version of Kibana, but I faced a problem in setting up my Development Environment. May you check this topic please. I'll appreciate that :slight_smile:

Warm regards.

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