Search in sources :

Example 1 with MatrixStats

use of org.opensearch.search.aggregations.matrix.stats.MatrixStats in project OpenSearch by opensearch-project.

the class SearchIT method testSearchWithMatrixStats.

public void testSearchWithMatrixStats() throws IOException {
    SearchRequest searchRequest = new SearchRequest("index");
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.aggregation(new MatrixStatsAggregationBuilder("agg1").fields(Arrays.asList("num", "num2")));
    searchSourceBuilder.size(0);
    searchRequest.source(searchSourceBuilder);
    SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
    assertSearchHeader(searchResponse);
    assertNull(searchResponse.getSuggest());
    assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
    assertEquals(5, searchResponse.getHits().getTotalHits().value);
    assertEquals(0, searchResponse.getHits().getHits().length);
    assertEquals(Float.NaN, searchResponse.getHits().getMaxScore(), 0f);
    assertEquals(1, searchResponse.getAggregations().asList().size());
    MatrixStats matrixStats = searchResponse.getAggregations().get("agg1");
    assertEquals(5, matrixStats.getFieldCount("num"));
    assertEquals(56d, matrixStats.getMean("num"), 0d);
    assertEquals(1830.0000000000002, matrixStats.getVariance("num"), 0d);
    assertEquals(0.09340198804973039, matrixStats.getSkewness("num"), 0d);
    assertEquals(1.2741646510794589, matrixStats.getKurtosis("num"), 0d);
    assertEquals(5, matrixStats.getFieldCount("num2"));
    assertEquals(29d, matrixStats.getMean("num2"), 0d);
    assertEquals(330d, matrixStats.getVariance("num2"), 0d);
    assertEquals(-0.13568039346585542, matrixStats.getSkewness("num2"), 1.0e-16);
    assertEquals(1.3517561983471071, matrixStats.getKurtosis("num2"), 0d);
    assertEquals(-767.5, matrixStats.getCovariance("num", "num2"), 0d);
    assertEquals(-0.9876336291667923, matrixStats.getCorrelation("num", "num2"), 0d);
}
Also used : MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) SearchRequest(org.opensearch.action.search.SearchRequest) MatrixStatsAggregationBuilder(org.opensearch.search.aggregations.matrix.stats.MatrixStatsAggregationBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse) MatrixStats(org.opensearch.search.aggregations.matrix.stats.MatrixStats)

Aggregations

MultiSearchRequest (org.opensearch.action.search.MultiSearchRequest)1 MultiSearchResponse (org.opensearch.action.search.MultiSearchResponse)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 MatrixStats (org.opensearch.search.aggregations.matrix.stats.MatrixStats)1 MatrixStatsAggregationBuilder (org.opensearch.search.aggregations.matrix.stats.MatrixStatsAggregationBuilder)1 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1