Search in sources :

Example 1 with FstStats

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));
}
Also used : FstStats(de.spinscale.elasticsearch.action.suggest.statistics.FstStats) UpdateSettingsResponse(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) ElasticsearchIntegrationTest(org.elasticsearch.test.ElasticsearchIntegrationTest)

Example 2 with FstStats

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;
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) FstStats(de.spinscale.elasticsearch.action.suggest.statistics.FstStats) ShardId(org.elasticsearch.index.shard.ShardId) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

FstStats (de.spinscale.elasticsearch.action.suggest.statistics.FstStats)2 Response (com.ning.http.client.Response)1 Map (java.util.Map)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ArrayNode (org.codehaus.jackson.node.ArrayNode)1 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)1 UpdateSettingsResponse (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse)1 Settings (org.elasticsearch.common.settings.Settings)1 ShardId (org.elasticsearch.index.shard.ShardId)1 ElasticsearchIntegrationTest (org.elasticsearch.test.ElasticsearchIntegrationTest)1 Test (org.junit.Test)1