Package org.elasticsearch.search.facet.statistical

Examples of org.elasticsearch.search.facet.statistical.StatisticalFacet


                    logger.warn("-> {}", shardSearchFailure);
                }
            }
            assertThat(searchResponse.failedShards(), equalTo(0));

            StatisticalFacet facet = searchResponse.facets().facet("stats1");
            assertThat(facet.name(), equalTo(facet.name()));
            assertThat(facet.count(), equalTo(2l));
            assertThat(facet.total(), equalTo(3d));
            assertThat(facet.min(), equalTo(1d));
            assertThat(facet.max(), equalTo(2d));
            assertThat(facet.mean(), equalTo(1.5d));
            assertThat(facet.sumOfSquares(), equalTo(5d));

            facet = searchResponse.facets().facet("stats2");
            assertThat(facet.name(), equalTo(facet.name()));
            assertThat(facet.count(), equalTo(4l));
            assertThat(facet.total(), equalTo(10d));
            assertThat(facet.min(), equalTo(1d));
            assertThat(facet.max(), equalTo(4d));
            assertThat(facet.mean(), equalTo(2.5d));

            facet = searchResponse.facets().facet("stats3");
            assertThat(facet.name(), equalTo(facet.name()));
            assertThat(facet.count(), equalTo(2l));
            assertThat(facet.total(), equalTo(6d));
            assertThat(facet.min(), equalTo(2d));
            assertThat(facet.max(), equalTo(4d));
            assertThat(facet.mean(), equalTo(3d));
            assertThat(facet.sumOfSquares(), equalTo(20d));

            // test multi field facet
            searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(statisticalFacet("stats").fields("num", "multi_num"))
                    .execute().actionGet();


            facet = searchResponse.facets().facet("stats");
            assertThat(facet.name(), equalTo(facet.name()));
            assertThat(facet.count(), equalTo(6l));
            assertThat(facet.total(), equalTo(13d));
            assertThat(facet.min(), equalTo(1d));
            assertThat(facet.max(), equalTo(4d));
            assertThat(facet.mean(), equalTo(13d / 6d));
            assertThat(facet.sumOfSquares(), equalTo(35d));

            // test cross field facet using the same facet name...
            searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(statisticalFacet("stats").field("num"))
                    .addFacet(statisticalFacet("stats").field("multi_num"))
                    .execute().actionGet();


            facet = searchResponse.facets().facet("stats");
            assertThat(facet.name(), equalTo(facet.name()));
            assertThat(facet.count(), equalTo(6l));
            assertThat(facet.total(), equalTo(13d));
            assertThat(facet.min(), equalTo(1d));
            assertThat(facet.max(), equalTo(4d));
            assertThat(facet.mean(), equalTo(13d / 6d));
            assertThat(facet.sumOfSquares(), equalTo(35d));
        }
    }
View Full Code Here


    @Test
    public void statisticalFacet() throws Exception {
        StatisticalFacetBuilder facet = FacetBuilders.statisticalFacet("f")
               .field("price");

        StatisticalFacet f = (StatisticalFacet) launchSearch(facet, "f");

        f.getCount();           // Doc count
        f.getMin();             // Min value
        f.getMax();             // Max value
        f.getMean();            // Mean
        f.getTotal();           // Sum of values
        f.getStdDeviation();    // Standard Deviation
        f.getSumOfSquares();    // Sum of Squares
        f.getVariance();        // Variance
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.facet.statistical.StatisticalFacet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.