我正在尝试使用JEST Client来搜索remotely located ElasticSearch index。
但是我遇到了一个问题 - 每一个查询,无论是使用各种构建器构建还是只是默认的ES查询,一切都返回 的 com.google.gson.stream.MalformedJsonException
代码:
String URL = "http://api.exiletools.com:80";
String API_KEY = "DEVELOPMENT-Indexer";
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(URL)
.defaultCredentials("apikey", API_KEY)
.build());
JestClient client = factory.getObject();
qb = QueryBuilders
.boolQuery()
.must(QueryBuilders.termQuery("attributes.league", "Standard"))
.must(new TermQueryBuilder("attributes.equipType", "Ring"))
.must(new TermQueryBuilder("shop.verified", "yes"));
searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(qb);
query = searchSourceBuilder.toString();
search = new Search.Builder(query).build();
client.execute(search); // Here I get the error
作为最终测试,我刚刚复制了我可以从Jest集成测试示例中找到的最小查询,只是替换了那里的搜索术语,如下所示:
query = "{\n"
+ " \"query\" : {\n"
+ " \"term\" : { \"shop.chaosEquiv\" : \"167\" }\n"
+ " }\n"
+ "}";
从输出流复制时,此查询如下所示:
{
"query" : {
"term" : { "shop.chaosEquiv" : "167" }
}
}
没有尾随的空格或任何内容,看起来对我有效。
仍然得到同样的错误。 谁能说出发生了什么?
答案 0 :(得分:0)
缺少索引和文档类型:
new Search.Builder(query).addIndex(searchIndex)
.addType(documentType)
.build();