Search in sources :

Example 76 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class BulkByScrollTaskTests method testXContentRepresentationOfUnlimitedRequestsPerSecond.

public void testXContentRepresentationOfUnlimitedRequestsPerSecond() throws IOException {
    XContentBuilder builder = JsonXContent.contentBuilder();
    BulkByScrollTask.Status status = new BulkByScrollTask.Status(null, 0, 0, 0, 0, 0, 0, 0, 0, 0, timeValueMillis(0), Float.POSITIVE_INFINITY, null, timeValueMillis(0));
    status.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertThat(builder.string(), containsString("\"requests_per_second\":-1"));
}
Also used : BulkByScrollTask(org.elasticsearch.action.bulk.byscroll.BulkByScrollTask) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 77 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class IndicesStatsTests method testSegmentStats.

public void testSegmentStats() throws Exception {
    XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("doc").startObject("properties").startObject("foo").field("type", "keyword").field("doc_values", true).field("store", true).endObject().startObject("bar").field("type", "text").field("term_vector", "with_positions_offsets_payloads").endObject().startObject("baz").field("type", "long").endObject().endObject().endObject().endObject();
    assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", mapping));
    ensureGreen("test");
    client().prepareIndex("test", "doc", "1").setSource("foo", "bar", "bar", "baz", "baz", 42).get();
    client().admin().indices().prepareRefresh("test").get();
    IndicesStatsResponse rsp = client().admin().indices().prepareStats("test").get();
    SegmentsStats stats = rsp.getIndex("test").getTotal().getSegments();
    assertThat(stats.getTermsMemoryInBytes(), greaterThan(0L));
    assertThat(stats.getStoredFieldsMemoryInBytes(), greaterThan(0L));
    assertThat(stats.getTermVectorsMemoryInBytes(), greaterThan(0L));
    assertThat(stats.getNormsMemoryInBytes(), greaterThan(0L));
    assertThat(stats.getPointsMemoryInBytes(), greaterThan(0L));
    assertThat(stats.getDocValuesMemoryInBytes(), greaterThan(0L));
    // now check multiple segments stats are merged together
    client().prepareIndex("test", "doc", "2").setSource("foo", "bar", "bar", "baz", "baz", 43).get();
    client().admin().indices().prepareRefresh("test").get();
    rsp = client().admin().indices().prepareStats("test").get();
    SegmentsStats stats2 = rsp.getIndex("test").getTotal().getSegments();
    assertThat(stats2.getTermsMemoryInBytes(), greaterThan(stats.getTermsMemoryInBytes()));
    assertThat(stats2.getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes()));
    assertThat(stats2.getTermVectorsMemoryInBytes(), greaterThan(stats.getTermVectorsMemoryInBytes()));
    assertThat(stats2.getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes()));
    assertThat(stats2.getPointsMemoryInBytes(), greaterThan(stats.getPointsMemoryInBytes()));
    assertThat(stats2.getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes()));
}
Also used : SegmentsStats(org.elasticsearch.index.engine.SegmentsStats) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 78 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class OldIndexBackwardsCompatibilityIT method testOldClusterStates.

public void testOldClusterStates() throws Exception {
    // dangling indices do not load the global state, only the per-index states
    // so we make sure we can read them separately
    MetaDataStateFormat<MetaData> globalFormat = new MetaDataStateFormat<MetaData>(XContentType.JSON, "global-") {

        @Override
        public void toXContent(XContentBuilder builder, MetaData state) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public MetaData fromXContent(XContentParser parser) throws IOException {
            return MetaData.Builder.fromXContent(parser);
        }
    };
    MetaDataStateFormat<IndexMetaData> indexFormat = new MetaDataStateFormat<IndexMetaData>(XContentType.JSON, "state-") {

        @Override
        public void toXContent(XContentBuilder builder, IndexMetaData state) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public IndexMetaData fromXContent(XContentParser parser) throws IOException {
            return IndexMetaData.Builder.fromXContent(parser);
        }
    };
    Collections.shuffle(indexes, random());
    for (String indexFile : indexes) {
        String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT).replace("unsupported-", "index-");
        Path nodeDir = getNodeDir(indexFile);
        logger.info("Parsing cluster state files from index [{}]", indexName);
        final MetaData metaData = globalFormat.loadLatestState(logger, xContentRegistry(), nodeDir);
        assertNotNull(metaData);
        final Version version = Version.fromString(indexName.substring("index-".length()));
        final Path dataDir;
        if (version.before(Version.V_5_0_0_alpha1)) {
            dataDir = nodeDir.getParent().getParent();
        } else {
            dataDir = nodeDir.getParent();
        }
        final Path indexDir = getIndexDir(logger, indexName, indexFile, dataDir);
        assertNotNull(indexFormat.loadLatestState(logger, xContentRegistry(), indexDir));
    }
}
Also used : MetaDataStateFormat(org.elasticsearch.gateway.MetaDataStateFormat) Path(java.nio.file.Path) Version(org.elasticsearch.Version) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 79 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class SearchScrollIT method assertToXContentResponse.

private void assertToXContentResponse(ClearScrollResponse response, boolean succeed, int numFreed) throws IOException {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
    assertThat(map.get("succeeded"), is(succeed));
    assertThat(map.get("num_freed"), equalTo(numFreed));
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 80 with XContentBuilder

use of org.elasticsearch.common.xcontent.XContentBuilder in project elasticsearch by elastic.

the class GeoDistanceIT method testGeoDistanceFilter.

/**
     * Issue 3073
     */
public void testGeoDistanceFilter() throws IOException {
    Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    double lat = 40.720611;
    double lon = -73.998776;
    XContentBuilder mapping = JsonXContent.contentBuilder().startObject().startObject("location").startObject("properties").startObject("pin").field("type", "geo_point");
    mapping.endObject().endObject().endObject().endObject();
    XContentBuilder source = JsonXContent.contentBuilder().startObject().field("pin", GeoHashUtils.stringEncode(lon, lat)).endObject();
    assertAcked(prepareCreate("locations").setSettings(settings).addMapping("location", mapping));
    client().prepareIndex("locations", "location", "1").setCreate(true).setSource(source).execute().actionGet();
    refresh();
    client().prepareGet("locations", "location", "1").execute().actionGet();
    SearchResponse result = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(QueryBuilders.geoDistanceQuery("pin").geoDistance(GeoDistance.ARC).point(lat, lon).distance("1m")).execute().actionGet();
    assertHitCount(result, 1);
}
Also used : Version(org.elasticsearch.Version) Settings(org.elasticsearch.common.settings.Settings) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)619 IOException (java.io.IOException)127 XContentParser (org.elasticsearch.common.xcontent.XContentParser)122 Settings (org.elasticsearch.common.settings.Settings)60 ArrayList (java.util.ArrayList)59 SearchResponse (org.elasticsearch.action.search.SearchResponse)56 Matchers.containsString (org.hamcrest.Matchers.containsString)53 HashMap (java.util.HashMap)47 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)43 Map (java.util.Map)41 RestRequest (org.elasticsearch.rest.RestRequest)37 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)36 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)35 Test (org.junit.Test)34 RestController (org.elasticsearch.rest.RestController)33 NodeClient (org.elasticsearch.client.node.NodeClient)32 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)32 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)32 GeoPoint (org.elasticsearch.common.geo.GeoPoint)31 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28