简体   繁体   中英

sending requests to elasticsearch through kibana without authentication

I am writing a plugin to kibana.

I want to be able to communicate with elasticsearch and I have shield installed.

For now, the only way I managed to do so, is by sending a request through the server such as:

server.route({
    method: 'GET',
    path: '/someFunction',
    handler: async function (request, reply) {
      const exec = require('child_process').exec;
      exec("curl --user admin:111111 -XPOST 'localhost:9200/filebeat-*/_search?pretty' -d ' { --someQuery-- }'", function (err, res) {
        if (err) {
          throw err;
        } else {
          console.log(JSON.parse(res));
          reply(JSON.parse(res));
        }
      });
    }
  });

I am sure there is a better way to do that, as I can see the esResp and the searchSource in other places in the code.

The authentication is already inserted in the login so there is no need for me to expose the password hard-coded in the server.

How do i do that? how to use the kibana built-in communication to elasticserach?

Ok got it..

return es.search({
          index: 'filebeat-*',
          body: {
            "size": 0,
            "aggs": {
              "group_by_product": {
                "terms": {
                  "field": "product"
                }
              }
            }
          }
        }).then(function (resp) {
          resp.aggregations.group_by_product.buckets.forEach(function (obj) {
          });
        });

Just needed to use the elasticsearch nodeJs module (es).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM