use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class GeoBoundingBoxQueryIT method testCompleteLonRange.
public void testCompleteLonRange() throws Exception {
Version version = VersionUtils.randomIndexCompatibleVersion(random());
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build();
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "geo_point");
xContentBuilder.endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder));
ensureGreen();
client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("userid", 880).field("title", "Place in Stockholm").startObject("location").field("lat", 59.328355000000002).field("lon", 18.036842).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
client().prepareIndex("test").setId("2").setSource(jsonBuilder().startObject().field("userid", 534).field("title", "Place in Montreal").startObject("location").field("lat", 45.509526999999999).field("lon", -73.570986000000005).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, -180, -50, 180)).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, -180, -50, 180).type("indexed")).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, -180, -90, 180)).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, -180, -90, 180).type("indexed")).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, 0, -50, 360)).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(50, 0, -50, 360).type("indexed")).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, 0, -90, 360)).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
searchResponse = client().prepareSearch().setQuery(geoBoundingBoxQuery("location").setValidationMethod(GeoValidationMethod.COERCE).setCorners(90, 0, -90, 360).type("indexed")).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L));
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class GeoBoundingBoxQueryIT method testLimit2BoundingBox.
public void testLimit2BoundingBox() throws Exception {
Version version = VersionUtils.randomIndexCompatibleVersion(random());
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build();
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "geo_point");
xContentBuilder.endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder));
ensureGreen();
client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("userid", 880).field("title", "Place in Stockholm").startObject("location").field("lat", 59.328355000000002).field("lon", 18.036842).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
client().prepareIndex("test").setId("2").setSource(jsonBuilder().startObject().field("userid", 534).field("title", "Place in Montreal").startObject("location").field("lat", 45.509526999999999).field("lon", -73.570986000000005).endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery().must(termQuery("userid", 880)).filter(geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(boolQuery().must(termQuery("userid", 880)).filter(geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875).type("indexed"))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(boolQuery().must(termQuery("userid", 534)).filter(geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch().setQuery(boolQuery().must(termQuery("userid", 534)).filter(geoBoundingBoxQuery("location").setCorners(74.579421999999994, 143.5, -66.668903999999998, 113.96875).type("indexed"))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class RemoteScrollableHitSourceTests method assertLookupRemoteVersion.
private void assertLookupRemoteVersion(Version expected, String s) throws Exception {
AtomicBoolean called = new AtomicBoolean();
sourceWithMockedRemoteCall(false, ContentType.APPLICATION_JSON, s).lookupRemoteVersion(wrapAsListener(v -> {
assertEquals(expected, v);
called.set(true);
}));
assertTrue(called.get());
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class RemoteRequestBuildersTests method testIntialSearchPath.
public void testIntialSearchPath() {
Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
BytesReference query = new BytesArray("{}");
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
assertEquals("/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
searchRequest.indices("a");
assertEquals("/a/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
searchRequest.indices("a", "b");
assertEquals("/a,b/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
searchRequest.indices("cat,");
assertEquals("/cat%2C/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
searchRequest.indices("cat/");
assertEquals("/cat%2F/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
searchRequest.indices("cat/", "dog");
assertEquals("/cat%2F,dog/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
// test a specific date math + all characters that need escaping.
searchRequest.indices("<cat{now/d}>", "<>/{}|+:,");
assertEquals("/%3Ccat%7Bnow%2Fd%7D%3E,%3C%3E%2F%7B%7D%7C%2B%3A%2C/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
// pass-through if already escaped.
searchRequest.indices("%2f", "%3a");
assertEquals("/%2f,%3a/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
assertWarnings(DEPRECATED_URL_ENCODED_INDEX_WARNING);
// do not allow , and / if already escaped.
searchRequest.indices("%2fcat,");
expectBadStartRequest(searchRequest, "Index", ",", "%2fcat,");
searchRequest.indices("%3ccat/");
expectBadStartRequest(searchRequest, "Index", "/", "%3ccat/");
}
use of org.opensearch.Version in project OpenSearch by opensearch-project.
the class RemoteRequestBuildersTests method expectBadStartRequest.
private void expectBadStartRequest(SearchRequest searchRequest, String type, String bad, String failed) {
Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
BytesReference query = new BytesArray("{}");
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> initialSearch(searchRequest, query, remoteVersion));
assertEquals(type + " containing [" + bad + "] not supported but got [" + failed + "]", e.getMessage());
}
Aggregations