我确信我错过了一些东西,但我正在尝试开始使用ElasticSearch。我使用www.searchly.com设置了一个远程搜索服务器,并使用ElasticSearch-js与其交互。我已经用searchly建立了一个索引,你可以看到它已经被填充了(如下面的截图所示)。

现在我在一个angular2组件中使用它,在我拥有的构造函数中:
constructor() {
var connectionString = 'http://xyz@bifur-eu-west-1.searchly.com';
this._client = new elasticsearch.Client({ host: connectionString, log: 'trace' });
}在ngOnInit生命周期钩子中,我有:
ngOnInit() {
this._client.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
}它工作得很好,显示集群是活动的,并且我的客户端成功地连接到它。但是,我随后将ping更改为:
this._client.search({
index: 'plugins',
type: '_all',
body: {
query: {
match: {
name: 'Contacts'
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});正如您从屏幕截图中看到的,它应该返回一个值,但我在浏览器的控制台中获得了以下内容:
TRACE: 2016-10-03T08:43:04Z
-> POST http://bifur-eu-west-1.searchly.com/plugins/_all/_search
{
"query": {
"match": {
"name": "Contacts"
}
}
}
<- 200
{
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
},
"took": 1,
"timed_out": false
}为什么这个查询没有返回结果呢?
发布于 2016-10-03 17:22:31
抓到了!事实证明,searchly有一个后端bug,它要求您在查询中使用显式type,或者根本不使用类型,因此可以更改为:
this._client.search({
index: 'plugins',
body: {
query: {
match: {
name: 'Contacts'
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});我得到了正确的结果!
https://stackoverflow.com/questions/39819488
复制相似问题