0

正如在 FullScale 的官方文档中看到的,我有:

// The official one
var elasticsearch = require('elasticsearch');

var client = new elasticsearch.Client({
    host: conf.elastic.server
});

// FullScale one (for some reasons, needing the official one, whereas in AngularJS, same version, used alone. But hey ! I'm not judging.
var ejs = require('elastic.js');

client.search({
    index: conf.elastic.indice,
    type: conf.elastic.index,
    body: ejs.Request().query(ejs.BoolQuery().must(ejs.MatchQuery('field': 'exemple'))
}).then(function(resp) {
    _this.sendResponse(null, resp.hits.hits, res);
}, function(args) {
    console.trace("Erreur #" + args.status + " : " + args.error);
});

一切似乎都有效,除非我仔细观察与“示例”完全无关的结果,例如:

{
    "field": "something that have absolutely nothing to do with anything"
},
{
    "field": "lolwut i don't even know how to elasticsearch"
},
{
    "field": "kthxbye"
}

elastic.js(全尺寸)在 npm 上是否损坏(因为我知道它在 AngularJS 上工作)?还是我忘记猜测 FullScale 文档中没有的内容?

谢谢。

4

1 回答 1

0

由于某些原因,我们现在需要使用 toString 方法,如下所示:

var body = ejs.Request().query(ejs.BoolQuery().must(ejs.MatchQuery('field': 'exemple'))

client.search({
    index: conf.elastic.indice,
    type: conf.elastic.index,
    body: body.toString()
}).then(...);

然后它就起作用了。

如果有人能真正解释为什么会这样,我会保持开放状态。不管怎么说,还是要谢谢你。

于 2014-04-01T08:44:40.550 回答