0
votes

i have a elasticsearch query result as

"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"}}]}}}

i want to print the source of each hit..."hits" is the result returned by the controller.

i tried it this way...but didn't seem to work

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

but this code worked...which prints the source of the first element of the array

<p> {{ hits.tops.hits.hits[0]._source }} </p>

is there any way of iterating through all the array elements and printing them??

2

2 Answers

1
votes

Your first attempt is close, you have a typo i think. Check this working fiddle

<div ng-repeat="hit in data.tops.hits.hits">
    <p > {{ hit._source.t_pacs_id }}</p>  
</div>

I copied your data and stored it in $scope.data.

Note: You should not use a <td> outside a <table>. Consider changing your HTML.

0
votes

It should work, here's an example Plnkr:

  <body ng-controller="MainCtrl">
    <div ng-repeat="hit in hits.tops.hits.hits">{{hit._source.t_pacs_id}}</div>
  </body>

Problem is probably that you are trying to display the data in td elements. td needs to be within a table and a table row.