Help using promises in javascript?

Hi I'm trying to create a flotchart with es but I don't quite know how to
resolve my promise. Here is the code. When I log the promise in my function
I show it's in a pending state but I don't understand how to resolve it AND
get the results into an object that I can then traverse response.hits.hits.

So I guess a few questions:
Do I resolve the promise in Main or in dashboardFlotTwo?
When I resolve it, how do I get the object out into a value I can work with?
Is there a better way to do this?

Any help appreciated.


function MainCtrl() {

promise = new Promise(function(resolve,reject){

  index: events,

  body: {  query: {  bool: { must : [ { range : { "@timestamp" : { "gt" 

: "now-8h" } } }

        ] //end must

      } //end bool

    } //end query

  } //end body




function dashboardFlotTwo() {




You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit