Search in sources :

Example 86 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class GeoPolygonIT method setupSuiteScopeCluster.

@Override
protected void setupSuiteScopeCluster() throws Exception {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    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();
    indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("name", "New York").startObject("location").field("lat", 40.714).field("lon", -74.006).endObject().endObject()), // to NY: 5.286 km
    client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("name", "Times Square").startObject("location").field("lat", 40.759).field("lon", -73.984).endObject().endObject()), // to NY: 0.4621 km
    client().prepareIndex("test", "type1", "3").setSource(jsonBuilder().startObject().field("name", "Tribeca").startObject("location").field("lat", 40.718).field("lon", -74.008).endObject().endObject()), // to NY: 1.055 km
    client().prepareIndex("test", "type1", "4").setSource(jsonBuilder().startObject().field("name", "Wall Street").startObject("location").field("lat", 40.705).field("lon", -74.009).endObject().endObject()), // to NY: 1.258 km
    client().prepareIndex("test", "type1", "5").setSource(jsonBuilder().startObject().field("name", "Soho").startObject("location").field("lat", 40.725).field("lon", -74).endObject().endObject()), // to NY: 2.029 km
    client().prepareIndex("test", "type1", "6").setSource(jsonBuilder().startObject().field("name", "Greenwich Village").startObject("location").field("lat", 40.731).field("lon", -73.996).endObject().endObject()), // to NY: 8.572 km
    client().prepareIndex("test", "type1", "7").setSource(jsonBuilder().startObject().field("name", "Brooklyn").startObject("location").field("lat", 40.65).field("lon", -73.95).endObject().endObject()));
    ensureSearchable("test");
}
Also used : Version(org.elasticsearch.Version) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 87 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class RemoteRequestBuildersTests method testInitialSearchParamsMisc.

public void testInitialSearchParamsMisc() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    Version remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
    TimeValue scroll = null;
    if (randomBoolean()) {
        scroll = TimeValue.parseTimeValue(randomPositiveTimeValue(), "test");
        searchRequest.scroll(scroll);
    }
    int size = between(0, Integer.MAX_VALUE);
    searchRequest.source().size(size);
    Boolean fetchVersion = null;
    if (randomBoolean()) {
        fetchVersion = randomBoolean();
        searchRequest.source().version(fetchVersion);
    }
    Map<String, String> params = initialSearchParams(searchRequest, remoteVersion);
    assertThat(params, scroll == null ? not(hasKey("scroll")) : hasEntry("scroll", scroll.toString()));
    assertThat(params, hasEntry("size", Integer.toString(size)));
    assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 88 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class RemoteRequestBuildersTests method testInitialSearchParamsFields.

public void testInitialSearchParamsFields() {
    SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
    // Test request without any fields
    Version remoteVersion = VersionUtils.randomVersion(random());
    assertThat(initialSearchParams(searchRequest, remoteVersion), not(either(hasKey("stored_fields")).or(hasKey("fields"))));
    // Setup some fields for the next two tests
    searchRequest.source().storedField("_source").storedField("_id");
    // Test stored_fields for versions that support it
    remoteVersion = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0_alpha4, null);
    assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("stored_fields", "_source,_id"));
    // Test fields for versions that support it
    remoteVersion = VersionUtils.randomVersionBetween(random(), null, Version.V_5_0_0_alpha3);
    assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("fields", "_source,_id"));
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Version(org.elasticsearch.Version) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 89 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class MainResponseTests method testToXContent.

public void testToXContent() throws IOException {
    Build build = new Build("buildHash", "2016-11-15".toString(), true);
    Version version = Version.V_2_4_5;
    MainResponse response = new MainResponse("nodeName", version, new ClusterName("clusterName"), "clusterUuid", build, true);
    XContentBuilder builder = XContentFactory.jsonBuilder();
    response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertEquals("{" + "\"name\":\"nodeName\"," + "\"cluster_name\":\"clusterName\"," + "\"cluster_uuid\":\"clusterUuid\"," + "\"version\":{" + "\"number\":\"2.4.5\"," + "\"build_hash\":\"buildHash\"," + "\"build_date\":\"2016-11-15\"," + "\"build_snapshot\":true," + "\"lucene_version\":\"5.5.2\"}," + "\"tagline\":\"You Know, for Search\"" + "}", builder.string());
}
Also used : Version(org.elasticsearch.Version) Build(org.elasticsearch.Build) ClusterName(org.elasticsearch.cluster.ClusterName) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 90 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class MainResponseTests method createTestItem.

public static MainResponse createTestItem() {
    String clusterUuid = randomAsciiOfLength(10);
    ClusterName clusterName = new ClusterName(randomAsciiOfLength(10));
    String nodeName = randomAsciiOfLength(10);
    Build build = new Build(randomAsciiOfLength(8), new Date(randomNonNegativeLong()).toString(), randomBoolean());
    Version version = VersionUtils.randomVersion(random());
    boolean available = randomBoolean();
    return new MainResponse(nodeName, version, clusterName, clusterUuid, build, available);
}
Also used : Version(org.elasticsearch.Version) Build(org.elasticsearch.Build) ClusterName(org.elasticsearch.cluster.ClusterName) Date(java.util.Date)

Aggregations

Version (org.elasticsearch.Version)124 Settings (org.elasticsearch.common.settings.Settings)51 StreamInput (org.elasticsearch.common.io.stream.StreamInput)21 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)20 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)14 IOException (java.io.IOException)13 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 List (java.util.List)11 Map (java.util.Map)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClusterName (org.elasticsearch.cluster.ClusterName)9 TimeValue (org.elasticsearch.common.unit.TimeValue)9 VersionUtils.randomVersion (org.elasticsearch.test.VersionUtils.randomVersion)9 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)8