我需要使用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);
但是这会从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请求?
答案 0 :(得分:1)
嗯,经过测试,我找到了一个解决方案:
Search search = new Search.Builder(query.toString().replaceAll("\\n|\\r", "")).addIndex(es_index_data)
.addType(es_type_data).build();