Javascript 弹性搜索+;未显示AngularJS结果
我在使用AngularJS显示elasticsearch客户端返回的数据时遇到问题。 我的html正文中有以下代码:Javascript 弹性搜索+;未显示AngularJS结果,javascript,html,angularjs,json,elasticsearch,Javascript,Html,Angularjs,Json,elasticsearch,我在使用AngularJS显示elasticsearch客户端返回的数据时遇到问题。 我的html正文中有以下代码: <div ng-app="elasticApp" ng-controller="elasticCtrl" class="container-fluid"> <div ng-repeat="x in hits"> {{ hits._id }} </div> </div> 我正在尝试显示elasticsearch客户端
<div ng-app="elasticApp" ng-controller="elasticCtrl" class="container-fluid">
<div ng-repeat="x in hits">
{{ hits._id }}
</div>
</div>
我正在尝试显示elasticsearch客户端返回的结果。
在控制台中,我可以看到JSON数据已正确返回:
TRACE: 2015-11-29T19:00:09Z
-> POST http://localhost:9200/riverindex/river/_search
{
"query": {
"match_all": {}
}
}
<- 200
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "riverindex",
"_type": "river",
"_id": "563e18e6d5603e015ca34165",
"_score": 1,
"_source": {
"test": "test",
"_id": "563e18e6d5603e015ca34165"
}
}
]
}
}
TRACE:2015-11-29T19:00:09Z
->职位http://localhost:9200/riverindex/river/_search
{
“查询”:{
“全部匹配”:{}
}
}
我认为你的观点应该是正确的
<div ng-app="elasticApp" ng-controller="elasticCtrl" class="container-fluid">
<div ng-repeat="x in hits">
{{ x._id }} <---- here
</div>
</div>
{{x._id}}好的,我找到了简单的解决方案,但这可能不是真正优雅的解决方案
在角度部分:
client.search({
index: 'riverindex',
type: 'river',
body: {
query: {
"match_all" : { }
}
}
}).then(function (resp) {
$scope.hits = resp.hits.hits;
$scope.$apply(function () {
});
}, function (err) {
console.trace(err.message);
});
是否从console.log($scope.hits)记录上述日志;或者只是显示请求/响应?上面的日志来自console.log($scope.hits);为什么选择console.log($scope.hits);显示完整响应,它应该只显示“hits”中的任何内容,请尝试console.log($scope.hits.hits)抱歉,我的错。我更新了这个主题的主要帖子。我从console.log($scope.hits);,附加了带有日志的打印屏幕;。第一篇文章中的JSON是来自elasticsearch的响应。console.log($scope.hits.hits)显示错误。您是对的,但它仍然无法工作:/不知道为什么
client.search({
index: 'riverindex',
type: 'river',
body: {
query: {
"match_all" : { }
}
}
}).then(function (resp) {
$scope.hits = resp.hits.hits;
$scope.$apply(function () {
});
}, function (err) {
console.trace(err.message);
});