0

I have JSON object returned from elastic search like below enter image description here

How can i get the Agent and calls value from this JSON.

$scope.results = client
                .query(oQuery.query($scope.queryTerm || '*'))
                .doSearch().then(function (body) {
             $scope.results = body.hits.hits;
             var resultstofilter = $scope.results;
             var log = [];
              angular.forEach(results, function(result, key) {
                angular.forEach(result, function(value, key) {
                   this.push(key + ': ' + value);
                 }, log);
              }, log);
             console.log(resultstofilter);
            }, function (error) {
              console.trace(error.message);
              });;

The above prints the same objects again and again.

1 Answer 1

1

Somewhere you need to filters the keys if you only want the "Agents" and "Calls" ones.

$scope.results = client
            .query(oQuery.query($scope.queryTerm || '*'))
            .doSearch().then(function (body) {
         $scope.results = body.hits.hits;
         var resultstofilter = [];

         for (var i=0; i<$scope.results.length; ++i) {
           var result = $scope.results[i];
           resultstofilter[i] = {};
           for (var key in result) {
             // If all you want are keys that doesn't start with '_'
             // you can also test key.substring(0, 1) !== '_'
             if (key === 'Agent' || key === 'Calls') {
               resultstofilter[i][key] = result[key];
             }
           }
         }

         console.log(resultstofilter);
        }, function (error) {
          console.trace(error.message);
        });;
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but am getting the key as 0,1,2,3,4
Sorry, it should be better now (no need for Object.keys)
ya now its better, but still does not go inside the object .they keys are actually id,_index,scope etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.