2016-06-21 80 views
0

我有一个elasticsearch查询结果迭代通过elasticsearch文件的数组,并打印出来

“强”:{

“命中”:{

“总”:21” MAX_SCORE “:2.2237754,

”命中“:[{” _索引 “:” automatch_testing”, “_类型”: “temp_135”, “_ ID”: “AVU7i0nnXK6g_oqHu-AZ”, “_分数”:2.2237754, “_源” :{“t_pacs_id”:“34”,“t_id”:“60”,“匹配”:“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”, “_分数”:2.2237754, “_源”:{ “t_pacs_id”: “28”, “T_ID”: “60”, “匹配”: “MO”, “UICriteria”: “135”,” t_match“:”matched“}}]}}}

我想打印每个命中的源...”命中“是控制器返回的结果。

我想是这样......但似乎没有工作

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

但是这个代码的工作...打印出数组的第一个元素的源

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

是否有任何方法遍历所有数组元素并打印它们?

回答

1

你的第一次尝试是接近,你有我认为的错字。 检查该工作fiddle

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

我复制你的数据并将其存储在$scope.data

注意:您不应该在<table>以外使用<td>。考虑改变你的HTML。

0

它应该工作,这里有一个例子Plnkr

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

问题可能是你试图显示在TD元素中的数据。 td需要位于表格和表格行内。