在JavaScript中的查询正文中使用Elasticsearch后终止 [英] Using elasticsearch terminate after in query body in javascript
问题描述
我正在尝试只为查询返回一个结果,我知道该查询可能返回多个结果,所以我想使用terminate_after参数,但是我无法弄清楚如何在查询主体中使用它在javascript中.我尝试将其放在正文中,如下所示,但我得到了 parsing_exception
:"[terminateAfter]中VALUE_NUMBER的未知键."
I am trying to get only one result back for a query I know may return more than one result, so I would like to use the the terminate_after parameter, but I can't work out how to use it in a query body in javascript. I have tried putting it in the body, like below, but I get a parsing_exception
: "Unknown key for a VALUE_NUMBER in [terminateAfter]."
client.search({
index: 'myindex',
type: 'mytype',
body: {
terminateAfter: 1,
query: {
term: {
searchField: searchString
}
}
}
}, function(error, results){}
我也尝试将其放入查询中,但这也会导致 parsing_exception
:"[terminateAfter]查询格式错误,查询名称后没有start_object"
I have also tried putting it inside the query, but this also causes a parsing_exception
: "[terminateAfter] query malformed, no start_object after query name"
我正在使用Elasticsearch 5.3版本和elasticsearch npm模块的13.3.1版本.
I am using version 5.3 of elasticsearch and version 13.3.1 of the elasticsearch npm module.
推荐答案
您几乎完全正确, terminateAfter
应该放在 body
之外,如下所示:
You've almost got it right, terminateAfter
should go outside the body
, like this:
client.search({
index: 'myindex',
type: 'mytype',
terminateAfter: 1,
body: {
query: {
term: {
searchField: searchString
}
}
}
}, function(error, results){}
这篇关于在JavaScript中的查询正文中使用Elasticsearch后终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!