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"));
}
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()));
}
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));
}
}
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));
}
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);
}
Aggregations