use of de.spinscale.elasticsearch.action.suggest.statistics.FstStats in project elasticsearch-suggest-plugin by spinscale.
the class AbstractSuggestTest method gettingStatisticsShouldWork.
@Test
public void gettingStatisticsShouldWork() throws Exception {
// needed to make sure that we hit the already queried shards for stats, the other are empty
Settings settings = settingsBuilder().put("index.number_of_replicas", 0).build();
UpdateSettingsResponse response = client().admin().indices().prepareUpdateSettings(index).setSettings(settings).get();
assertThat(response.isAcknowledged(), is(true));
List<Map<String, Object>> products = createProducts("ProductName", "BMW 318", "BMW 528", "BMW M3", "the BMW 320", "VW Jetta");
indexProducts(products);
FstStats emptyFstStats = getStatistics();
assertThat(emptyFstStats.getStats(), hasSize(0));
assertThat(getFstSizeSum(emptyFstStats), equalTo(0L));
SuggestionQuery query = new SuggestionQuery(index, type, "ProductName.keyword", "b").suggestType("full").analyzer("stop").size(10);
List<String> suggestions = getSuggestions(query);
assertSuggestions(suggestions, "BMW 318", "BMW 528", "BMW M3", "the BMW 320");
FstStats filledFstStats = getStatistics();
assertThat(filledFstStats.getStats(), hasSize(greaterThanOrEqualTo(1)));
List<FstStats.FstIndexShardStats> allStats = Lists.newArrayList(filledFstStats.getStats());
assertThat(allStats.get(0).getShardId().id(), greaterThanOrEqualTo(0));
assertThat(getFstSizeSum(filledFstStats), greaterThan(0L));
}
use of de.spinscale.elasticsearch.action.suggest.statistics.FstStats in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method getStatistics.
@Override
public FstStats getStatistics() throws Exception {
List<FstStats.FstIndexShardStats> stats = Lists.newArrayList();
Response r = httpClient.prepareGet("http://localhost:" + port + "/__suggestStatistics").execute().get();
assertThat(r.getStatusCode(), is(200));
System.out.println(r.getResponseBody());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootObj = objectMapper.readTree(r.getResponseBody());
FstStats fstStats = new FstStats();
ArrayNode jsonFstStats = (ArrayNode) rootObj.get("fstStats");
Iterator<JsonNode> nodesIterator = jsonFstStats.iterator();
while (nodesIterator.hasNext()) {
JsonNode fstStatsNodeEntry = nodesIterator.next();
if (fstStatsNodeEntry.isObject()) {
ShardId shardId = new ShardId(fstStatsNodeEntry.get("index").asText(), fstStatsNodeEntry.get("id").asInt());
FstStats.FstIndexShardStats fstIndexShardStats = new FstStats.FstIndexShardStats(shardId, null, null, fstStatsNodeEntry.get("sizeInBytes").getLongValue());
stats.add(fstIndexShardStats);
}
fstStats.getStats().addAll(stats);
}
return fstStats;
}
Aggregations