Nihal Pratap Nihal Pratap - 5 months ago 15
AngularJS Question

Accessing array of elasticsearch documents with AngularJS

i have the query result as follows...

{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 45,
"max_score": 0,
"hits": []
},
"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",
"UICriteria": "135",
"t_match": "matched",
"t_criteria": "Accession Number;Patient Identifier;Last Name;Date of Birth;Sex;Modality"
}
},
{
"_index": "automatch_testing",
"_type": "temp_143",
"_id": "AVU7iOSeXK6g_oqHu-XY",
"_score": 2.2237754,
"_source": {
"t_pacs_id": "30",
"t_id": "60",
"matching": "MO",
"UICriteria": "143",
"t_match": "matched",
"t_criteria": "Accession Number;Patient Identifier;Last Name"
}
},
{
"_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",
"t_criteria": "Accession Number;Patient Identifier;Last Name;Date of Birth;Sex;Modality"
}
}
]
}
}
},
{
"key": "12",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 2.2237754,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoC9XK6g_oqHvAal",
"_score": 2.2237754,
"_source": {
"t_pacs_id": "778",
"t_id": "12",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkQyjsrQd4jgajJ",
"_score": 2.098612,
"_source": {
"t_pacs_id": "654",
"t_id": "12",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkOyjsrQd4jgajI",
"_score": 1.9007865,
"_source": {
"t_pacs_id": "778",
"t_id": "12",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
},
{
"key": "22",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 2.098612,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkXyjsrQd4jgajM",
"_score": 2.098612,
"_source": {
"t_pacs_id": "778",
"t_id": "22",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoDLXK6g_oqHvAaq",
"_score": 1.9007865,
"_source": {
"t_pacs_id": "654",
"t_id": "22",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkYyjsrQd4jgajN",
"_score": 1.8690379,
"_source": {
"t_pacs_id": "654",
"t_id": "22",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
},
{
"key": "48",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 2.098612,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkGyjsrQd4jgajG",
"_score": 2.098612,
"_source": {
"t_pacs_id": "778",
"t_id": "48",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoCyXK6g_oqHvAaj",
"_score": 1.7621399,
"_source": {
"t_pacs_id": "778",
"t_id": "48",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoCzXK6g_oqHvAak",
"_score": 1.7621399,
"_source": {
"t_pacs_id": "654",
"t_id": "48",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
},
{
"key": "83",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 2.098612,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoDVXK6g_oqHvAas",
"_score": 2.098612,
"_source": {
"t_pacs_id": "654",
"t_id": "83",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkeyjsrQd4jgajP",
"_score": 2.098612,
"_source": {
"t_pacs_id": "654",
"t_id": "83",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoDUXK6g_oqHvAar",
"_score": 1.8690379,
"_source": {
"t_pacs_id": "778",
"t_id": "83",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
},
{
"key": "90",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 2.2237754,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXj_yjsrQd4jgajE",
"_score": 2.2237754,
"_source": {
"t_pacs_id": "778",
"t_id": "90",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoCtXK6g_oqHvAai",
"_score": 2.098612,
"_source": {
"t_pacs_id": "654",
"t_id": "90",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoCrXK6g_oqHvAah",
"_score": 1.9007865,
"_source": {
"t_pacs_id": "778",
"t_id": "90",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
},
{
"key": "945",
"doc_count": 4,
"tops": {
"hits": {
"total": 4,
"max_score": 1.9007865,
"hits": [
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkTyjsrQd4jgajK",
"_score": 1.9007865,
"_source": {
"t_pacs_id": "778",
"t_id": "945",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_121",
"_id": "AVU9LoDEXK6g_oqHvAao",
"_score": 1.8690379,
"_source": {
"t_pacs_id": "654",
"t_id": "945",
"matching": "MO",
"UICriteria": "121",
"t_match": "matched",
"t_criteria": "Middle Name"
}
},
{
"_index": "automatch_testing",
"_type": "temp_144",
"_id": "AVVTNXkUyjsrQd4jgajL",
"_score": 1.8690379,
"_source": {
"t_pacs_id": "654",
"t_id": "945",
"matching": "MO",
"UICriteria": "144",
"t_match": "matched",
"t_criteria": "Middle Name"
}
}
]
}
}
}
]
}
}
}


i want to display a table like for each "key" all the documents under that key is printed...
the first result would be

_________________________
key | t_pacs_id
_________________________
60 | 34
| 30
| 28
-------------------------
12 | 778
| 654


i have this code plunkr

but the code only prints the "key" not the "t_pacs_id"...is it possible to do this??
if so please suggest.

many thanks.

Answer

Replacing:

      <tr ng-repeat="hit in fhits">             
          <td> {{ hit.key}} </td>
          -<div data-ng-repeat="i in range">
              <div ng-repeat="rhit in hit.tops.hits.hits">
                        <td > {{ rhit }} </td>
              </div>
          </div>
      </tr>

With:

      <tr ng-repeat="hit in fhits">

          <td> {{hit.key}} </td>

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

Should give you what you are looking for.

Plunker