.setSize(2)
.setQuery(QueryBuilders.termQuery("_all", "data"))
.addField("content");
// with hits (default)
ClusteringActionResponse resultWithHits = new ClusteringActionRequestBuilder(client)
.setQueryHint("data mining")
.setAlgorithm("stc")
.addFieldMapping("title", LogicalField.TITLE)
.setSearchRequest(req)
.execute().actionGet();
checkValid(resultWithHits);
checkJsonSerialization(resultWithHits);
// get JSON output
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
resultWithHits.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
JSONObject jsonWithHits = new JSONObject(builder.string());
Assertions.assertThat(jsonWithHits.has("hits")).isTrue();
// without hits
ClusteringActionResponse resultWithoutHits = new ClusteringActionRequestBuilder(client)
.setQueryHint("data mining")
.setIncludeHits("false")
.setAlgorithm("stc")
.addFieldMapping("title", LogicalField.TITLE)
.setSearchRequest(req)
.execute().actionGet();
checkValid(resultWithoutHits);
checkJsonSerialization(resultWithoutHits);
// get JSON output
builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
resultWithoutHits.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
JSONObject jsonWithoutHits = new JSONObject(builder.string());
Assertions.assertThat(
jsonWithoutHits
.getJSONObject("hits")