如何在 Jest 中使用 MultiSearch API 执行请求?
How to perform request with MultiSearch API in Jest?
我需要使用来自 Jest 的 MultiSearch API 提出一些请求。
我尝试像这样构建搜索请求:
Search search = new Search.Builder(query).addIndex(index).addType(type).build();
然后,我将所有这些请求添加到一个集合中,以构建 MultiSearch 并获得结果,如下所示:
List<Search> ms = new ArrayList<Search>();
for (#iterate over#) {
ms.add(search())
//Adding the searches queries to the List
}
MultiSearch multi = new MultiSearch.Builder(ms).build();
MultiSearchResult multir = client.execute(multi);
但是这个 return 这个来自 elasticsearch 的错误:
{
"error": {
"caused_by": {
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2ccf4bb6; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2ccf4bb6; line: 2, column: 3]",
"type": "json_e_o_f_exception"
},
"reason": "Exception when parsing search request",
"root_cause": [
{
"reason": "Exception when parsing search request",
"type": "parse_exception"
}
],
"type": "parse_exception"
},
"status": 400
}
所以我的问题是,如何用 jest 执行 MultiSearch 请求?
好吧,经过测试,我找到了解决办法:
Search search = new Search.Builder(query.toString().replaceAll("\n|\r", "")).addIndex(es_index_data)
.addType(es_type_data).build();
我需要使用来自 Jest 的 MultiSearch API 提出一些请求。 我尝试像这样构建搜索请求:
Search search = new Search.Builder(query).addIndex(index).addType(type).build();
然后,我将所有这些请求添加到一个集合中,以构建 MultiSearch 并获得结果,如下所示:
List<Search> ms = new ArrayList<Search>();
for (#iterate over#) {
ms.add(search())
//Adding the searches queries to the List
}
MultiSearch multi = new MultiSearch.Builder(ms).build();
MultiSearchResult multir = client.execute(multi);
但是这个 return 这个来自 elasticsearch 的错误:
{
"error": {
"caused_by": {
"reason": "Unexpected end-of-input: expected close marker for Object (start marker at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2ccf4bb6; line: 1, column: 1])\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@2ccf4bb6; line: 2, column: 3]",
"type": "json_e_o_f_exception"
},
"reason": "Exception when parsing search request",
"root_cause": [
{
"reason": "Exception when parsing search request",
"type": "parse_exception"
}
],
"type": "parse_exception"
},
"status": 400
}
所以我的问题是,如何用 jest 执行 MultiSearch 请求?
好吧,经过测试,我找到了解决办法:
Search search = new Search.Builder(query.toString().replaceAll("\n|\r", "")).addIndex(es_index_data)
.addType(es_type_data).build();