3

The PhraseSuggestionBuilder in 1.6.0 of the elasticsearch java API has a collateQuery method that takes a String.

builder
  .collateQuery("\"match\": {\"title\" : \"{{suggestion}}\"}")
  .collatePrune(true);

Unfortunately the escaped quotes are escaped by the builder to produce JSON like this:

"collate" : {
    "query" : "\"match\": {\"title\" : \"{{suggestion}}\"}",
    "prune" : true
 }

Anyone any ideas how I can stop this String being escaped as the JSON is generated?

Thanks.

Tim
  • 435
  • 1
  • 4
  • 12
  • I ended up using the RestTemplate pattern and not using the Java API at all. Digging though the 1.6.0 elasticsearch code, I can't see how to avoid the double escaping of the collate query. `String text = String.format(config.getQueryTemplate(), query.getText().toLowerCase()); String url = addTypes(getIndexUrl(), types) + "/_search"; try { return rest.postForObject(url, text, String.class); } catch (HttpClientErrorException e) { LOG.error("Unable to search: {}", e.getResponseBodyAsString(), e); throw e; }` – Tim Jul 29 '15 at 08:14

0 Answers0