Search in sources :

Example 11 with GeoPoint

use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.

the class GeoBoundsIT method testSingleValuedFieldWithZeroLon.

public void testSingleValuedFieldWithZeroLon() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_ZERO_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).get();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 12 with GeoPoint

use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.

the class GeoBoundsIT method testEmptyAggregation.

public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch(EMPTY_IDX_NAME).setQuery(matchAllQuery()).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).get();
    assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L));
    GeoBounds geoBounds = searchResponse.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft, equalTo(null));
    assertThat(bottomRight, equalTo(null));
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 13 with GeoPoint

use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.

the class GeoBoundsIT method testSingleValuedFieldNearDateLine.

public void testSingleValuedFieldNearDateLine() throws Exception {
    SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).get();
    assertSearchResponse(response);
    GeoPoint geoValuesTopLeft = new GeoPoint(38, -179);
    GeoPoint geoValuesBottomRight = new GeoPoint(-24, 178);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 14 with GeoPoint

use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.

the class GeoBoundsIT method testPartiallyUnmapped.

public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch(IDX_NAME, UNMAPPED_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).get();
    assertSearchResponse(response);
    GeoBounds geoBounds = response.getAggregations().get(aggName);
    assertThat(geoBounds, notNullValue());
    assertThat(geoBounds.getName(), equalTo(aggName));
    GeoPoint topLeft = geoBounds.topLeft();
    GeoPoint bottomRight = geoBounds.bottomRight();
    assertThat(topLeft.lat(), closeTo(singleTopLeft.lat(), GEOHASH_TOLERANCE));
    assertThat(topLeft.lon(), closeTo(singleTopLeft.lon(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lat(), closeTo(singleBottomRight.lat(), GEOHASH_TOLERANCE));
    assertThat(bottomRight.lon(), closeTo(singleBottomRight.lon(), GEOHASH_TOLERANCE));
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 15 with GeoPoint

use of org.opensearch.common.geo.GeoPoint in project OpenSearch by opensearch-project.

the class ContextCompletionSuggestSearchIT method testGeoFiltering.

public void testGeoFiltering() throws Exception {
    LinkedHashMap<String, ContextMapping<?>> map = new LinkedHashMap<>();
    map.put("geo", ContextBuilder.geo("geo").build());
    final CompletionMappingBuilder mapping = new CompletionMappingBuilder().context(map);
    createIndexAndMapping(mapping);
    int numDocs = 10;
    List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
    GeoPoint[] geoPoints = new GeoPoint[] { new GeoPoint("ezs42e44yx96"), new GeoPoint("u4pruydqqvj8") };
    for (int i = 0; i < numDocs; i++) {
        XContentBuilder source = jsonBuilder().startObject().startObject(FIELD).field("input", "suggestion" + i).field("weight", i + 1).startObject("contexts").field("geo", (i % 2 == 0) ? geoPoints[0].getGeohash() : geoPoints[1].getGeohash()).endObject().endObject().endObject();
        indexRequestBuilders.add(client().prepareIndex(INDEX).setId("" + i).setSource(source));
    }
    indexRandom(true, indexRequestBuilders);
    CompletionSuggestionBuilder geoFilteringPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").contexts(Collections.singletonMap("geo", Collections.singletonList(GeoQueryContext.builder().setGeoPoint(new GeoPoint(geoPoints[0])).build())));
    assertSuggestions("foo", geoFilteringPrefix, "suggestion8", "suggestion6", "suggestion4", "suggestion2", "suggestion0");
}
Also used : ArrayList(java.util.ArrayList) GeoPoint(org.opensearch.common.geo.GeoPoint) LinkedHashMap(java.util.LinkedHashMap) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) CompletionSuggestionBuilder(org.opensearch.search.suggest.completion.CompletionSuggestionBuilder) GeoPoint(org.opensearch.common.geo.GeoPoint) ContextMapping(org.opensearch.search.suggest.completion.context.ContextMapping) GeoContextMapping(org.opensearch.search.suggest.completion.context.GeoContextMapping) CategoryContextMapping(org.opensearch.search.suggest.completion.context.CategoryContextMapping) CompletionMappingBuilder(org.opensearch.search.suggest.CompletionSuggestSearchIT.CompletionMappingBuilder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

GeoPoint (org.opensearch.common.geo.GeoPoint)150 SearchResponse (org.opensearch.action.search.SearchResponse)41 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)27 ArrayList (java.util.ArrayList)23 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)19 Matchers.containsString (org.hamcrest.Matchers.containsString)11 XContentParser (org.opensearch.common.xcontent.XContentParser)10 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)10 LatLonPoint (org.apache.lucene.document.LatLonPoint)8 Version (org.opensearch.Version)8 IOException (java.io.IOException)7 LatLonDocValuesField (org.apache.lucene.document.LatLonDocValuesField)7 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)7 OpenSearchParseException (org.opensearch.OpenSearchParseException)7 Range (org.opensearch.search.aggregations.bucket.range.Range)6 Bucket (org.opensearch.search.aggregations.bucket.range.Range.Bucket)6 Map (java.util.Map)5 Document (org.apache.lucene.document.Document)5 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 Query (org.apache.lucene.search.Query)5