module.exports = function(kibana) {
  return new kibana.Plugin({

    // Export the front-end visualization definition.
    uiExports: {
      visTypes: [
        "plugins/kibana-chord/chord"
      ]
    },

    // Define our custom server-side middleware for
    // custom ElasticSearch queries.
    init: function (server, options) {
      server.route({
        path: "/api/kibana-chord",
        method: "POST",
        handler: function(req, reply) {

          // The payload can be expected to have the following properties:
          //
          // * d.index - Name of the ES index to query.
          // * d.time - Parameters from the global Kibana time selector.
          // * d.source - Value for the source of the clicked ribbon.
          // * d.destination - Value for the destination of the clicked ribbon.
          var d = req.payload;

          // Unpack the query parameters from the client.
          var index = req.payload.index;
          var time = req.payload.time;

          // TODO include sourceField, destField from client Schema config
          var options = {
            index: index,
            scroll: "30s",
            body: {
              sort: [
                { "timestamp": { "order": "desc" } }
              ],
              query: {
                bool: {
                  should: [
        	  {
           	    "bool": {
             	      "must": [
                        {"term": {"nuage_metadata.sourcepolicygroups": d.source} },
                        { "term": {"nuage_metadata.destinationpolicygroups": d.destination} },
                        {"range": { "timestamp": time }}
                      ]
                    }
                  },
                  {
                    "bool": {
                      "must": [
                        { "term": {"nuage_metadata.sourcepolicygroups": d.destination} },
                        { "term": {"nuage_metadata.destinationpolicygroups": d.source} },
                        {"range": { "timestamp": time }}
                      ] 
                    }
                  }
                 ]
                }
              }
            }
          };
          // Execute the query and pass it to the client as JSON.
          server.plugins.elasticsearch
            .callWithRequest(req, "search", options)
            .then(function (response) {
              reply(JSON.stringify(response, null, 2));
            });
        }
      });
    }

  });
};

@@ -328,16 +328,70 @@
 tions) %7B
+%0A%0A      // This route is for the initial search query.
 %0A      s
@@ -2506,24 +2506,274 @@
  %7D%0A      %7D);
+%0A%0A      // This route is for scrolling through results.%0A      server.route(%7B%0A        path: %22/api/kibana-chord-scroll%22,%0A        method: %22POST%22,%0A        handler: function(req, reply) %7B%0A          console.log(%22Inside Scroll Handler%22);%0A        %7D%0A      %7D);
 %0A    %7D%0A%0A  %7D)

Add new middleware route for scrolling