2

I am trying to use a JEST Client to search the remotely located ElasticSearch index.

However I've ran into a problem - every single query, be it constructed using various builders or just default ES queries, everything returns com.google.gson.stream.MalformedJsonException

Code:

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

As a final test I just copied the smallest query I could find from Jest integration test examples and just replaced the search terms there, to look like:

        query = "{\n"
                + "    \"query\" : {\n"
                + "        \"term\" : { \"shop.chaosEquiv\" : \"167\" }\n"
                + "    }\n"
                + "}";

This query when copied from the output stream looks like this:

{
    "query" : {
        "term" : { "shop.chaosEquiv" : "167" }
    }
}

No trailing whitespaces or anything, looks valid to me.

Still getting the same error. Can anyone tell what is going on?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Shajirr
  • 164
  • 3
  • 14
  • 1
    Are you sure the ES cluster you're trying to reach is up and running? `MalformedJsonException` could be raised if ES is behind a proxy and/or the requests times out, what gets back is usually HTML and not JSON, hence why the JSON parser has trouble with it. Can you show how you're setting up your `client`? – Val Sep 22 '15 at 06:45
  • Code example added. The cluster is running, I have a Python script which the owner of the service created as an [example to test the connection](http://exiletools.com/blog/2015/08/25/tutorial-creating-a-simple-item-availability-notification-script-with-python/), and it works fine. – Shajirr Sep 22 '15 at 15:22

0 Answers0