2
我試圖使用JEST Client來搜索remotely located ElasticSearch index。ElasticSearch Jest客戶端使用:MalformedJsonException對任何查詢
但是我遇到了一個問題 - 每一個查詢,無論是構建使用各種建設者或只是默認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
作爲最後的測試我只是複製我能從玩笑集成測試的例子找到最小的查詢和剛剛更換了搜索詞在那裏,看起來像:
query = "{\n"
+ " \"query\" : {\n"
+ " \"term\" : { \"shop.chaosEquiv\" : \"167\" }\n"
+ " }\n"
+ "}";
該查詢將從輸出流複印的情況是這樣的:
{
"query" : {
"term" : { "shop.chaosEquiv" : "167" }
}
}
沒有尾隨空格或任何東西,看起來有效的給我。
仍然收到相同的錯誤。 誰能告訴發生了什麼事?
你確定你想達到ES集羣啓動並運行?如果ES位於代理之後,並且/或者請求超時,返回的內容通常是HTML而不是JSON,那麼可能會引發'MalformedJsonException',因此JSON解析器爲什麼會遇到問題。你能告訴你如何設置你的客戶端嗎? – Val
已添加代碼示例。羣集正在運行,我有一個Python腳本,服務的所有者創建了一個[用於測試連接的示例](http://exiletools.com/blog/2015/08/25/tutorial-creating-a-simple -item-availability-notification-script-with-python /),它工作正常。 – Shajirr