Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

i ran the following query..

 ExampleApp.controller('EXcont', function ($scope, client, esFactory) {        
    client.search({         
            index: 'automatch_testing',
            body: {
          "query": {
            "match": {
              matching: "MO"
            }
          }, 

          "size": 0, 
          "aggs":{
            "by_id":{
              "terms": {
                field: "t_id",
                "size": 0
              },
              "aggs": {
                "tops": {
                  "top_hits": {

                  }
                }
              }
            }
 }).then(function (response) {
      $scope.fhits = response.aggregations.by_id.buckets;              
    console.log($scope.fhits);
    }).catch(function (err) {
    $scope.clusterState = null;
    $scope.error = err;
}

and got the following result..i used console.log to check if it actually returned a result.

"aggregations": { "by_id": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ {

{"key":"60","doc_count":21,

"tops":{

"hits":{

"total":21,"max_score":2.2237754,

"hits":[{"_index":"automatch_testing","_type":"temp_135","_id":"AVU7i0nnXK6g_oqHu-az","_score":2.2237754,"_source":{"t_pacs_id":"34","t_id":"60","matching":"MO"}},

{"_index":"automatch_testing","_type":"temp_143","_id":"AVU7iOSeXK6g_oqHu-XY","_score":2.2237754,"_source":{"t_pacs_id":"30","t_id":"60","matching":"MO","t_match":"matched"}},

{"_index":"automatch_testing","_type":"temp_135","_id":"AVU7i0nlXK6g_oqHu-ay","_score":2.2237754,"_source":{"t_pacs_id":"28","t_id":"60","matching":"MO","UICriteria":"135","t_match":"matched"}}]}}}

but in the HMTL code this does not print anything..

   <div ng-controller="EXcont">
    <tr ng-repeat="hit in fhits">
       <td> {{ hit.key }} </td>
       <div ng-repeat="rhit in hit.tops.hits.hits">
     <td> {{ rhit._source.t_pacs_id }}</td>
     </div>
    </div>
    </tr>

i get this error

TypeError: Cannot read property 'hits' of undefined

am i doing this right??

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.