Angular JS + elasticsearch Query - Response


(Vivek) #1

I have the following program which is working fine , the issue is when i introduce ng-repeat tag. The results are not getting printed ...

I'm sorry to be verbose but wanted to provide all details to see if iam missing something overhere.

Code

Elasticsearch + Angular Example

Angular + Elasticsearch

<!-- if there is an error, display its message -->
<div ng-if="error" class="alert alert-danger" role="alert">{{error.message}}</div>

<!-- if clusterState is available, display it as formatted json -->
<div ng-if="clusterState" class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">Cluster State</h3>
  </div>
  <div class="panel-body">
    <pre>{{clusterState | json}}</pre>
  </div>
</div>
<div class="container-fluid">
<div class="row-fluid">
	<span class="span3">
		<input class="input-block-level" ng-model="queryTerm" type="text">
	</span>&nbsp;
	<button ng-click="search()" class="btn" type="button">Search</button>
</div>
<div ng-if="results" class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">Results</h3>
  </div>
                  <table>
				  <thead>
                 <tr>
                    <th>Name</th>
                    <th>Marks</th>
                 </tr>
				 </thead>
				 <tbody>
                 <!---- This is not working -->
				 <tr ng-repeat = "subject in results._source.entityAttributes">
                    <td>{{ subject.legacyEntityAttributeName }}</td>
                    <td>{{ subject.legacydataType }}</td>
                 </tr>
				</tbody>		
              </table>    
		<div class="panel-body">
				<!-- This prints the Jason beautifully see output--> 
				<pre>{{results | json}}</pre>
			</div>
		</div>
    </div>
============

output

Results
NameMarks [
{
"_index": "legacytables",
"_type": "existingtables",
"_id": "AVNC54hNO04QfeJDGYBX",
"_score": 3.9704144,
"_source": {
"dbEntityName": "TAAGENT_REMARK",
"otherEntityName": [
"pc_account",
"pc_note",
""
],
"entityAttributes": [
{
"legacyEntityAttributeName": "HOUSEHOLD_NUM",
"legacydataType": "CHAR",
"legacydatalength": "10.0",
"legacydataDefinition": "A unique system generated number which is used to identify a specific household.",
"legacydataClassification": "",
"dataTeamReviewComments": "",
"functionalTeamReviewComments": "",
"xmlTag": "",
"mappingLastUpdatedDate": "",
"mappingLastUpdatedBy": "",
"gwentityAttributeName": "AccountNumber",
"gwtableName": "pc_account",
"gwdataType": "Varchar(255)",
"gwdatalength": "Varchar(255)",
"mappedBy": "",
"mappedDate": "",
"team": "",
"gwdataDefinition": "The account number of this account. ",
"gwdataClassification": ""
},////Ignoring others for brevity
]
}
}
]


(Shaunak Kashyap) #2

The JSON output shows an outer array of all the results and within each result there is array, _source.entityAttributes. Yet you only have one ng-repeat loop.

I think you need an outer ng-repeat loop to loop over all the results and an inner ng-repeat loop to loop over _source.entityAttributes within each result.


(Vivek) #4

Iam doing that only please see my code
response object is set to resp.hits.hits and then ng repeat iam trying to get from _source.entityAttributes only.

I'm skipping the first loop by setting the response object.


(system) #5