Package org.elasticsearch.search.facet.geodistance

Examples of org.elasticsearch.search.facet.geodistance.GeoDistanceFacet


                        .addUnboundedTo(1)
                )
                .execute().actionGet();

        assertThat(searchResponse.hits().totalHits(), equalTo(7l));
        GeoDistanceFacet facet = searchResponse.facets().facet("geo1");
        assertThat(facet.entries().size(), equalTo(4));

        assertThat(facet.entries().get(0).to(), closeTo(2, 0.000001));
        assertThat(facet.entries().get(0).count(), equalTo(4l));
        assertThat(facet.entries().get(0).total(), not(closeTo(0, 0.00001)));

        assertThat(facet.entries().get(1).from(), closeTo(0, 0.000001));
        assertThat(facet.entries().get(1).to(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(1).count(), equalTo(2l));
        assertThat(facet.entries().get(1).total(), not(closeTo(0, 0.00001)));

        assertThat(facet.entries().get(2).from(), closeTo(0.5, 0.000001));
        assertThat(facet.entries().get(2).to(), closeTo(2.5, 0.000001));
        assertThat(facet.entries().get(2).count(), equalTo(3l));
        assertThat(facet.entries().get(2).total(), not(closeTo(0, 0.00001)));

        assertThat(facet.entries().get(3).from(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(3).count(), equalTo(5l));
        assertThat(facet.entries().get(3).total(), not(closeTo(0, 0.00001)));


        searchResponse = client.prepareSearch() // from NY
                .setQuery(matchAllQuery())
                .addFacet(geoDistanceFacet("geo1").field("location").point(40.7143528, -74.0059731).unit(DistanceUnit.KILOMETERS).valueField("num")
                        .addUnboundedFrom(2)
                        .addRange(0, 1)
                        .addRange(0.5, 2.5)
                        .addUnboundedTo(1)
                )
                .execute().actionGet();

        assertThat(searchResponse.hits().totalHits(), equalTo(7l));
        facet = searchResponse.facets().facet("geo1");
        assertThat(facet.entries().size(), equalTo(4));

        assertThat(facet.entries().get(0).to(), closeTo(2, 0.000001));
        assertThat(facet.entries().get(0).count(), equalTo(4l));
        assertThat(facet.entries().get(0).total(), closeTo(13, 0.00001));

        assertThat(facet.entries().get(1).from(), closeTo(0, 0.000001));
        assertThat(facet.entries().get(1).to(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(1).count(), equalTo(2l));
        assertThat(facet.entries().get(1).total(), closeTo(4, 0.00001));

        assertThat(facet.entries().get(2).from(), closeTo(0.5, 0.000001));
        assertThat(facet.entries().get(2).to(), closeTo(2.5, 0.000001));
        assertThat(facet.entries().get(2).count(), equalTo(3l));
        assertThat(facet.entries().get(2).total(), closeTo(15, 0.00001));

        assertThat(facet.entries().get(3).from(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(3).count(), equalTo(5l));
        assertThat(facet.entries().get(3).total(), closeTo(24, 0.00001));

        searchResponse = client.prepareSearch() // from NY
                .setQuery(matchAllQuery())
                .addFacet(geoDistanceFacet("geo1").field("location").point(40.7143528, -74.0059731).unit(DistanceUnit.KILOMETERS).valueScript("doc['num'].value")
                        .addUnboundedFrom(2)
                        .addRange(0, 1)
                        .addRange(0.5, 2.5)
                        .addUnboundedTo(1)
                )
                .execute().actionGet();

        assertThat(searchResponse.hits().totalHits(), equalTo(7l));
        facet = searchResponse.facets().facet("geo1");
        assertThat(facet.entries().size(), equalTo(4));

        assertThat(facet.entries().get(0).to(), closeTo(2, 0.000001));
        assertThat(facet.entries().get(0).count(), equalTo(4l));
        assertThat(facet.entries().get(0).total(), closeTo(13, 0.00001));

        assertThat(facet.entries().get(1).from(), closeTo(0, 0.000001));
        assertThat(facet.entries().get(1).to(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(1).count(), equalTo(2l));
        assertThat(facet.entries().get(1).total(), closeTo(4, 0.00001));

        assertThat(facet.entries().get(2).from(), closeTo(0.5, 0.000001));
        assertThat(facet.entries().get(2).to(), closeTo(2.5, 0.000001));
        assertThat(facet.entries().get(2).count(), equalTo(3l));
        assertThat(facet.entries().get(2).total(), closeTo(15, 0.00001));

        assertThat(facet.entries().get(3).from(), closeTo(1, 0.000001));
        assertThat(facet.entries().get(3).count(), equalTo(5l));
        assertThat(facet.entries().get(3).total(), closeTo(24, 0.00001));
    }
View Full Code Here


                .execute().actionGet();

        assertThat(Arrays.toString(searchResponse.shardFailures()), searchResponse.failedShards(), equalTo(0));

        assertThat(searchResponse.hits().totalHits(), equalTo(2l));
        GeoDistanceFacet facet = searchResponse.facets().facet("geo1");
        assertThat(facet.entries().size(), equalTo(2));

        assertThat(facet.entries().get(0).from(), closeTo(0, 0.000001));
        assertThat(facet.entries().get(0).to(), closeTo(2, 0.000001));
        assertThat(facet.entries().get(0).count(), equalTo(2l));

        assertThat(facet.entries().get(1).from(), closeTo(2, 0.000001));
        assertThat(facet.entries().get(1).to(), closeTo(10, 0.000001));
        assertThat(facet.entries().get(1).count(), equalTo(1l));
    }
View Full Code Here

                .addRange(20, 100)
                .addUnboundedTo(100)
                .unit(DistanceUnit.KILOMETERS)
                ;

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

        // For each entry
        for (GeoDistanceFacet.Entry entry : f) {
            entry.getFrom();            // Distance from requested
            entry.getTo();              // Distance to requested
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.facet.geodistance.GeoDistanceFacet

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.