Search in sources :

Example 11 with Version

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));
}
Also used : Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 12 with Version

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));
}
Also used : Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 13 with Version

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());
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) TimeValue.timeValueMinutes(org.opensearch.common.unit.TimeValue.timeValueMinutes) URL(java.net.URL) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) Version(org.opensearch.Version) FileSystemUtils(org.opensearch.common.io.FileSystemUtils) StatusLine(org.apache.http.StatusLine) Mockito.doThrow(org.mockito.Mockito.doThrow) Future(java.util.concurrent.Future) BackoffPolicy(org.opensearch.action.bulk.BackoffPolicy) After(org.junit.After) RestClient(org.opensearch.client.RestClient) HttpAsyncRequestProducer(org.apache.http.nio.protocol.HttpAsyncRequestProducer) ParsingException(org.opensearch.common.ParsingException) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) Response(org.opensearch.index.reindex.ScrollableHitSource.Response) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) RestStatus(org.opensearch.rest.RestStatus) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) StandardCharsets(java.nio.charset.StandardCharsets) ScrollableHitSource(org.opensearch.index.reindex.ScrollableHitSource) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) Stream(java.util.stream.Stream) BytesArray(org.opensearch.common.bytes.BytesArray) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) RejectAwareActionListener(org.opensearch.index.reindex.RejectAwareActionListener) Queue(java.util.Queue) Mockito.any(org.mockito.Mockito.any) Mockito.mock(org.mockito.Mockito.mock) TimeValue.timeValueMillis(org.opensearch.common.unit.TimeValue.timeValueMillis) ContentTooLongException(org.apache.http.ContentTooLongException) BasicStatusLine(org.apache.http.message.BasicStatusLine) ThreadPool(org.opensearch.threadpool.ThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpAsyncResponseConsumer(org.apache.http.nio.protocol.HttpAsyncResponseConsumer) Answer(org.mockito.stubbing.Answer) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LegacyESVersion(org.opensearch.LegacyESVersion) Streams(org.opensearch.common.io.Streams) SearchRequest(org.opensearch.action.search.SearchRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) Matchers.empty(org.hamcrest.Matchers.empty) FutureCallback(org.apache.http.concurrent.FutureCallback) IOException(java.io.IOException) HeapBufferedAsyncResponseConsumer(org.opensearch.client.HeapBufferedAsyncResponseConsumer) Mockito.when(org.mockito.Mockito.when) InputStreamReader(java.io.InputStreamReader) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) ProtocolVersion(org.apache.http.ProtocolVersion) HttpResponse(org.apache.http.HttpResponse) InputStreamEntity(org.apache.http.entity.InputStreamEntity) HttpHost(org.apache.http.HttpHost) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 14 with Version

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/");
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) SearchRequest(org.opensearch.action.search.SearchRequest) BytesArray(org.opensearch.common.bytes.BytesArray) Version(org.opensearch.Version) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder)

Example 15 with Version

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());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) BytesArray(org.opensearch.common.bytes.BytesArray) Version(org.opensearch.Version)

Aggregations

Version (org.opensearch.Version)242 Settings (org.opensearch.common.settings.Settings)86 LegacyESVersion (org.opensearch.LegacyESVersion)84 ArrayList (java.util.ArrayList)59 IOException (java.io.IOException)54 List (java.util.List)54 Map (java.util.Map)50 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)42 Collections (java.util.Collections)39 HashMap (java.util.HashMap)38 ClusterState (org.opensearch.cluster.ClusterState)38 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)37 HashSet (java.util.HashSet)36 BytesReference (org.opensearch.common.bytes.BytesReference)36 TimeValue (org.opensearch.common.unit.TimeValue)36 Set (java.util.Set)35 Collectors (java.util.stream.Collectors)34 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)33 StreamInput (org.opensearch.common.io.stream.StreamInput)32 BytesArray (org.opensearch.common.bytes.BytesArray)30