Package org.elasticsearch.action.search

Examples of org.elasticsearch.action.search.SearchResponse$Fields


                    .endObject()).execute().actionGet();
        }
        client.admin().indices().prepareRefresh().execute().actionGet();

        for (int i = 0; i < numberOfRuns(); i++) {
            SearchResponse searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(termsFacet("facet1").field("text").size(10))
                    .execute().actionGet();

            TermsFacet facet = searchResponse.facets().facet("facet1");
            assertThat(facet.name(), equalTo("facet1"));
            assertThat(facet.entries().size(), equalTo(3));
            for (int j = 0; j < 3; j++) {
                assertThat(facet.entries().get(j).term(), anyOf(equalTo("foo"), equalTo("bar"), equalTo("baz")));
                assertThat(facet.entries().get(j).count(), equalTo(10));
View Full Code Here


        client1.index(indexRequest("test").type("type1").id("2").source(source("2", "bar test")).refresh(true)).actionGet();
        client1.index(indexRequest("test").type("type1").id("3").source(source("3", "baz test")).refresh(true)).actionGet();
        client1.index(indexRequest("test").type("type1").id("4").source(source("4", "something else")).refresh(true)).actionGet();

        logger.info("--> checking single filtering alias search");
        SearchResponse searchResponse = client1.prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1");

        searchResponse = client1.prepareSearch("tests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3");

        searchResponse = client1.prepareSearch("foos", "bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2");

        logger.info("--> checking single non-filtering alias search");
        searchResponse = client1.prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3", "4");

        logger.info("--> checking non-filtering alias and filtering alias search");
        searchResponse = client1.prepareSearch("alias1", "foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3", "4");

        logger.info("--> checking index and filtering alias search");
        searchResponse = client1.prepareSearch("test", "foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3", "4");
    }
View Full Code Here

                .startArray("multi_num").value(3.0).value(4.0f).endArray()
                .endObject()).execute().actionGet();
        client.admin().indices().prepareRefresh().execute().actionGet();

        for (int i = 0; i < numberOfRuns(); i++) {
            SearchResponse searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(statisticalFacet("stats1").field("num"))
                    .addFacet(statisticalFacet("stats2").field("multi_num"))
                    .addFacet(statisticalScriptFacet("stats3").script("doc['num'].value * 2"))
                    .execute().actionGet();

            if (searchResponse.failedShards() > 0) {
                logger.warn("Failed shards:");
                for (ShardSearchFailure shardSearchFailure : searchResponse.shardFailures()) {
                    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));
View Full Code Here

        client1.index(indexRequest("test2").type("type1").id("6").source(source("6", "bar test")).refresh(true)).actionGet();
        client1.index(indexRequest("test2").type("type1").id("7").source(source("7", "baz test")).refresh(true)).actionGet();
        client1.index(indexRequest("test2").type("type1").id("8").source(source("8", "something else")).refresh(true)).actionGet();

        logger.info("--> checking filtering alias for two indices");
        SearchResponse searchResponse = client1.prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "5");
        assertThat(client1.prepareCount("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(2L));

        logger.info("--> checking filtering alias for one index");
        searchResponse = client1.prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "2");
        assertThat(client1.prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(1L));

        logger.info("--> checking filtering alias for two indices and one complete index");
        searchResponse = client1.prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3", "4", "5");
        assertThat(client1.prepareCount("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(5L));

        logger.info("--> checking filtering alias for two indices and non-filtering alias for one index");
        searchResponse = client1.prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "1", "2", "3", "4", "5");
        assertThat(client1.prepareCount("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(5L));

        logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
        searchResponse = client1.prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertThat(searchResponse.hits().totalHits(), equalTo(8L));
        assertThat(client1.prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(8L));

        logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
        searchResponse = client1.prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).execute().actionGet();
        assertHits(searchResponse.hits(), "4", "8");
        assertThat(client1.prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).execute().actionGet().count(), equalTo(2L));
    }
View Full Code Here

        client1.index(indexRequest("test3").type("type1").id("31").source(source("31", "foo test3")).refresh(true)).actionGet();
        client1.index(indexRequest("test3").type("type1").id("32").source(source("32", "bar test3")).refresh(true)).actionGet();
        client1.index(indexRequest("test3").type("type1").id("33").source(source("33", "baz test3")).refresh(true)).actionGet();

        logger.info("--> checking filtering alias for multiple indices");
        SearchResponse searchResponse = client1.prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "21", "31", "13", "33");
        assertThat(client1.prepareCount("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(4L));

        searchResponse = client1.prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "21", "31", "11", "12", "13");
        assertThat(client1.prepareCount("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(5L));

        searchResponse = client1.prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "11", "12", "13", "33");
        assertThat(client1.prepareCount("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(4L));

        searchResponse = client1.prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "11", "12", "13", "21", "31", "33");
        assertThat(client1.prepareCount("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(6L));

        searchResponse = client1.prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "21", "22", "23", "31", "13", "33");
        assertThat(client1.prepareCount("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(6L));

        searchResponse = client1.prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "11", "12", "13", "21", "22", "23", "31", "33");
        assertThat(client1.prepareCount("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(8L));

    }
View Full Code Here

        logger.info("--> delete by query from an aliases pointing to two indices");
        client1.prepareDeleteByQuery("foos").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        client1.admin().indices().prepareRefresh().execute().actionGet();

        logger.info("--> verify that proper records were deleted");
        SearchResponse searchResponse = client1.prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "3", "4", "6", "7", "8");

        logger.info("--> delete by query from an aliases and an index");
        client1.prepareDeleteByQuery("tests", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        client1.admin().indices().prepareRefresh().execute().actionGet();

        logger.info("--> verify that proper records were deleted");
        searchResponse = client1.prepareSearch("aliasToTests").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
        assertHits(searchResponse.hits(), "4");
    }
View Full Code Here

                .field("num", 300)
                .endObject()).execute().actionGet();
        client.admin().indices().prepareFlush().setRefresh(true).execute().actionGet();

        for (int i = 0; i < numberOfRuns(); i++) {
            SearchResponse searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(histogramFacet("facet1").field("num").valueField("num").interval(100))
                    .execute().actionGet();

            if (searchResponse.failedShards() > 0) {
                logger.warn("Failed shards:");
                for (ShardSearchFailure shardSearchFailure : searchResponse.shardFailures()) {
                    logger.warn("-> {}", shardSearchFailure);
                }
            }
            assertThat(searchResponse.failedShards(), equalTo(0));

            HistogramFacet facet = searchResponse.facets().facet("facet1");
            assertThat(facet.name(), equalTo("facet1"));
            assertThat(facet.entries().size(), equalTo(3));
            assertThat(facet.entries().get(0).key(), equalTo(100l));
            assertThat(facet.entries().get(0).count(), equalTo(1l));
            assertThat(facet.entries().get(1).key(), equalTo(200l));
View Full Code Here

                .startArray("multi_num").value(17.0f).value(25.0f).endArray()
                .endObject()).execute().actionGet();
        client.admin().indices().prepareRefresh().execute().actionGet();

        for (int i = 0; i < numberOfRuns(); i++) {
            SearchResponse searchResponse = client.prepareSearch()
                    .setQuery(matchAllQuery())
                    .addFacet(histogramFacet("stats1").field("num").valueField("num").interval(100))
                    .addFacet(histogramFacet("stats2").field("multi_num").valueField("multi_num").interval(10))
                    .addFacet(histogramFacet("stats3").keyField("num").valueField("multi_num").interval(100))
                    .addFacet(histogramScriptFacet("stats4").keyScript("doc['date'].date.minuteOfHour").valueScript("doc['num'].value"))
                    .addFacet(histogramFacet("stats5").field("date").interval(1, TimeUnit.MINUTES))
                    .addFacet(histogramScriptFacet("stats6").keyField("num").valueScript("doc['num'].value").interval(100))
                    .addFacet(histogramFacet("stats7").field("num").interval(100))
                    .addFacet(histogramScriptFacet("stats8").keyField("num").valueScript("doc.score").interval(100))
                    .addFacet(histogramFacet("stats9").field("num").bounds(1000, 1200).interval(100))
                    .addFacet(histogramFacet("stats10").field("num").bounds(1000, 1300).interval(100)) // for bounded, we also get 0s
                    .addFacet(histogramFacet("stats11").field("num").valueField("num").bounds(1000, 1300).interval(100)) // for bounded, we also get 0s
                    .addFacet(histogramScriptFacet("stats12").keyField("num").valueScript("doc['num'].value").bounds(1000, 1300).interval(100))  // for bounded, we also get 0s
                    .addFacet(histogramFacet("stats13").field("num").bounds(1056, 1176).interval(100))
                    .addFacet(histogramFacet("stats14").field("num").valueField("num").bounds(1056, 1176).interval(100))
                    .execute().actionGet();

            if (searchResponse.failedShards() > 0) {
                logger.warn("Failed shards:");
                for (ShardSearchFailure shardSearchFailure : searchResponse.shardFailures()) {
                    logger.warn("-> {}", shardSearchFailure);
                }
            }
            assertThat(searchResponse.failedShards(), equalTo(0));

            HistogramFacet facet;

            facet = searchResponse.facets().facet("stats1");
            assertThat(facet.name(), equalTo("stats1"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).min(), closeTo(1055d, 0.000001));
            assertThat(facet.entries().get(0).max(), closeTo(1065d, 0.000001));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2120d));
            assertThat(facet.entries().get(0).mean(), equalTo(1060d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).min(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).max(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1175d));
            assertThat(facet.entries().get(1).mean(), equalTo(1175d));

            facet = searchResponse.facets().facet("stats2");
            assertThat(facet.name(), equalTo("stats2"));
            assertThat(facet.entries().size(), equalTo(3));
            assertThat(facet.entries().get(0).key(), equalTo(10l));
            assertThat(facet.entries().get(0).count(), equalTo(3l));
            assertThat(facet.entries().get(0).totalCount(), equalTo(3l));
            assertThat(facet.entries().get(0).total(), equalTo(45d));
            assertThat(facet.entries().get(0).mean(), equalTo(15d));
            assertThat(facet.entries().get(1).key(), equalTo(20l));
            assertThat(facet.entries().get(1).count(), equalTo(2l));
            assertThat(facet.entries().get(1).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(1).total(), equalTo(48d));
            assertThat(facet.entries().get(1).mean(), equalTo(24d));
            assertThat(facet.entries().get(2).key(), equalTo(30l));
            assertThat(facet.entries().get(2).count(), equalTo(1l));
            assertThat(facet.entries().get(2).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(2).total(), equalTo(31d));
            assertThat(facet.entries().get(2).mean(), equalTo(31d));

            facet = searchResponse.facets().facet("stats3");
            assertThat(facet.name(), equalTo("stats3"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).totalCount(), equalTo(4l));
            assertThat(facet.entries().get(0).total(), equalTo(82d));
            assertThat(facet.entries().get(0).mean(), equalTo(20.5d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(1).total(), equalTo(42d));
            assertThat(facet.entries().get(1).mean(), equalTo(21d));

            facet = searchResponse.facets().facet("stats4");
            assertThat(facet.name(), equalTo("stats4"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(0l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2120d));
            assertThat(facet.entries().get(0).mean(), equalTo(1060d));
            assertThat(facet.entries().get(1).key(), equalTo(2l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1175d));
            assertThat(facet.entries().get(1).mean(), equalTo(1175d));

            facet = searchResponse.facets().facet("stats5");
            assertThat(facet.name(), equalTo("stats5"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(0l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(1).key(), equalTo(TimeValue.timeValueMinutes(2).millis()));
            assertThat(facet.entries().get(1).count(), equalTo(1l));

            facet = searchResponse.facets().facet("stats6");
            assertThat(facet.name(), equalTo("stats6"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2120d));
            assertThat(facet.entries().get(0).mean(), equalTo(1060d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1175d));
            assertThat(facet.entries().get(1).mean(), equalTo(1175d));

            facet = searchResponse.facets().facet("stats7");
            assertThat(facet.name(), equalTo("stats7"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));

            facet = searchResponse.facets().facet("stats8");
            assertThat(facet.name(), equalTo("stats8"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2d));
            assertThat(facet.entries().get(0).mean(), equalTo(1d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1d));
            assertThat(facet.entries().get(1).mean(), equalTo(1d));

            facet = searchResponse.facets().facet("stats9");
            assertThat(facet.name(), equalTo("stats9"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));

            facet = searchResponse.facets().facet("stats10");
            assertThat(facet.name(), equalTo("stats10"));
            assertThat(facet.entries().size(), equalTo(3));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(2).key(), equalTo(1200l));
            assertThat(facet.entries().get(2).count(), equalTo(0l));

            facet = searchResponse.facets().facet("stats11");
            assertThat(facet.name(), equalTo("stats11"));
            assertThat(facet.entries().size(), equalTo(3));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).min(), closeTo(1055d, 0.000001));
            assertThat(facet.entries().get(0).max(), closeTo(1065d, 0.000001));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2120d));
            assertThat(facet.entries().get(0).mean(), equalTo(1060d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).min(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).max(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1175d));
            assertThat(facet.entries().get(1).mean(), equalTo(1175d));
            assertThat(facet.entries().get(2).key(), equalTo(1200l));
            assertThat(facet.entries().get(2).count(), equalTo(0l));
            assertThat(facet.entries().get(2).totalCount(), equalTo(0l));

            facet = searchResponse.facets().facet("stats12");
            assertThat(facet.name(), equalTo("stats12"));
            assertThat(facet.entries().size(), equalTo(3));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(2l));
            assertThat(facet.entries().get(0).min(), closeTo(1055d, 0.000001));
            assertThat(facet.entries().get(0).max(), closeTo(1065d, 0.000001));
            assertThat(facet.entries().get(0).totalCount(), equalTo(2l));
            assertThat(facet.entries().get(0).total(), equalTo(2120d));
            assertThat(facet.entries().get(0).mean(), equalTo(1060d));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));
            assertThat(facet.entries().get(1).min(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).max(), closeTo(1175d, 0.000001));
            assertThat(facet.entries().get(1).totalCount(), equalTo(1l));
            assertThat(facet.entries().get(1).total(), equalTo(1175d));
            assertThat(facet.entries().get(1).mean(), equalTo(1175d));
            assertThat(facet.entries().get(2).key(), equalTo(1200l));
            assertThat(facet.entries().get(2).count(), equalTo(0l));
            assertThat(facet.entries().get(2).totalCount(), equalTo(0l));

            facet = searchResponse.facets().facet("stats13");
            assertThat(facet.name(), equalTo("stats13"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(1l));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
            assertThat(facet.entries().get(1).count(), equalTo(1l));

            facet = searchResponse.facets().facet("stats14");
            assertThat(facet.name(), equalTo("stats14"));
            assertThat(facet.entries().size(), equalTo(2));
            assertThat(facet.entries().get(0).key(), equalTo(1000l));
            assertThat(facet.entries().get(0).count(), equalTo(1l));
            assertThat(facet.entries().get(1).key(), equalTo(1100l));
View Full Code Here

                .query(matchAllQuery())
                .explain(true);

        Set<String> collectedIds = Sets.newHashSet();

        SearchResponse searchResponse = client.search(searchRequest("test").source(source.from(0).size(60)).searchType(QUERY_THEN_FETCH)).actionGet();
        assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0));
        assertThat(searchResponse.hits().totalHits(), equalTo(100l));
        assertThat(searchResponse.hits().hits().length, equalTo(60));
        for (int i = 0; i < 60; i++) {
            SearchHit hit = searchResponse.hits().hits()[i];
            collectedIds.add(hit.id());
        }
        searchResponse = client.search(searchRequest("test").source(source.from(60).size(60)).searchType(QUERY_THEN_FETCH)).actionGet();
        assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0));
        assertThat(searchResponse.hits().totalHits(), equalTo(100l));
        assertThat(searchResponse.hits().hits().length, equalTo(40));
        for (int i = 0; i < 40; i++) {
            SearchHit hit = searchResponse.hits().hits()[i];
            collectedIds.add(hit.id());
        }
        assertThat(collectedIds, equalTo(fullExpectedIds));
    }
View Full Code Here

                .field("dvalue", 0.2)
                .endObject()).execute().actionGet();

        client.admin().indices().prepareFlush().setRefresh(true).execute().actionGet();

        SearchResponse searchResponse = client.prepareSearch()
                .setQuery(matchAllQuery())
                .addSort("svalue", SortOrder.ASC)
                .execute().actionGet();

        assertThat(searchResponse.hits().getMaxScore(), equalTo(Float.NaN));
        for (SearchHit hit : searchResponse.hits()) {
            assertThat(hit.getScore(), equalTo(Float.NaN));
        }

        // now check with score tracking
        searchResponse = client.prepareSearch()
                .setQuery(matchAllQuery())
                .addSort("svalue", SortOrder.ASC)
                .setTrackScores(true)
                .execute().actionGet();

        assertThat(searchResponse.hits().getMaxScore(), not(equalTo(Float.NaN)));
        for (SearchHit hit : searchResponse.hits()) {
            assertThat(hit.getScore(), not(equalTo(Float.NaN)));
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.search.SearchResponse$Fields

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.