javascript - Getting subset of json from ElasticSearch -
i want have subset of json response elasticsearch server. new elasticsearch , javascript. please have look. json file example file here elasticsearch doc. sample:
{ "took" : 1, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1000, "max_score" : 1.0, "hits" : [ { "_index" : "bank", "_type" : "account", "_id" : "4", "_score" : 1.0, "_source":{"account_number":4,"balance":27658,"firstname":"rodriquez","lastname":"flores","age":31,"gender":"f","address":"986 wyckoff avenue","employer":"tourmania","email":"rodriquezflores@tourmania.com","city":"eastvale","state":"hi"} }, { "_index" : "bank", "_type" : "account", "_id" : "9", "_score" : 1.0, "_source":{"account_number":9,"balance":24776,"firstname":"opal","lastname":"meadows","age":39,"gender":"m","address":"963 neptune avenue","employer":"cedward","email":"opalmeadows@cedward.com","city":"olney","state":"oh"} } ................................ ] } }
how extract array of account_number, balance , lastname example [{"account_number":9,"balance":24776,"lastname":"meadows"},{"account_number":4,"balance":27658,"lastname":"flores"}, ......... ]
.
here code used:
var deferred = $q.defer(); $http.get("http://localhost:9200/bank/_search?q=*").success(function(data){ var country=data.hits.hists.map( function (count) { return { account_number: count._source.account_number, balance: count._source.balance, lastname: count._source.lastname }; }); deferred.resolve(country); }); return deferred.promise;
i took inspiration similar codes one rest call. seems data
got undefined
. there configuration es side?
you can instruct es return fields using source filtering:
$http.get("http://localhost:9200/bank/_search?_source=account_number,balance,lastname&q=*").success(function(data){
that way don't have filter out fields yourself.
then have typo on next line: hists
should read hits
var country=data.hits.hits.map( function (count) {
please try out.
Comments
Post a Comment