|
@@ -12,14 +12,18 @@ import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
import org.elasticsearch.cluster.metadata.Metadata;
|
|
|
import org.elasticsearch.common.Strings;
|
|
|
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
+import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.tasks.TaskCancelledException;
|
|
|
import org.elasticsearch.test.AbstractWireSerializingTestCase;
|
|
|
+import org.elasticsearch.test.VersionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
@@ -66,6 +70,18 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
" \"type\": \"keyword\"" +
|
|
|
" }" +
|
|
|
" }" +
|
|
|
+ " }," +
|
|
|
+ " \"long3\": {" +
|
|
|
+ " \"type\":\"long\"," +
|
|
|
+ " \"script\": " + Strings.toString(script3) +
|
|
|
+ " }," +
|
|
|
+ " \"long4\": {" +
|
|
|
+ " \"type\":\"long\"," +
|
|
|
+ " \"script\": " + Strings.toString(script4) +
|
|
|
+ " }," +
|
|
|
+ " \"keyword3\": {" +
|
|
|
+ " \"type\": \"keyword\"," +
|
|
|
+ " \"script\": " + Strings.toString(script1) +
|
|
|
" }" +
|
|
|
" }" +
|
|
|
"}";
|
|
@@ -78,13 +94,43 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
" \"field_types\" : [\n" +
|
|
|
" {\n" +
|
|
|
" \"name\" : \"keyword\",\n" +
|
|
|
- " \"count\" : 2,\n" +
|
|
|
- " \"index_count\" : 2\n" +
|
|
|
+ " \"count\" : 4,\n" +
|
|
|
+ " \"index_count\" : 2,\n" +
|
|
|
+ " \"script_count\" : 2,\n" +
|
|
|
+ " \"lang\" : [\n" +
|
|
|
+ " \"painless\"\n" +
|
|
|
+ " ],\n" +
|
|
|
+ " \"lines_max\" : 1,\n" +
|
|
|
+ " \"lines_total\" : 2,\n" +
|
|
|
+ " \"chars_max\" : 47,\n" +
|
|
|
+ " \"chars_total\" : 94,\n" +
|
|
|
+ " \"source_max\" : 1,\n" +
|
|
|
+ " \"source_total\" : 2,\n" +
|
|
|
+ " \"doc_max\" : 2,\n" +
|
|
|
+ " \"doc_total\" : 4\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"name\" : \"long\",\n" +
|
|
|
+ " \"count\" : 4,\n" +
|
|
|
+ " \"index_count\" : 2,\n" +
|
|
|
+ " \"script_count\" : 4,\n" +
|
|
|
+ " \"lang\" : [\n" +
|
|
|
+ " \"painless\"\n" +
|
|
|
+ " ],\n" +
|
|
|
+ " \"lines_max\" : 2,\n" +
|
|
|
+ " \"lines_total\" : 6,\n" +
|
|
|
+ " \"chars_max\" : 68,\n" +
|
|
|
+ " \"chars_total\" : 176,\n" +
|
|
|
+ " \"source_max\" : 3,\n" +
|
|
|
+ " \"source_total\" : 8,\n" +
|
|
|
+ " \"doc_max\" : 0,\n" +
|
|
|
+ " \"doc_total\" : 0\n" +
|
|
|
" },\n" +
|
|
|
" {\n" +
|
|
|
" \"name\" : \"object\",\n" +
|
|
|
" \"count\" : 2,\n" +
|
|
|
- " \"index_count\" : 2\n" +
|
|
|
+ " \"index_count\" : 2,\n" +
|
|
|
+ " \"script_count\" : 0\n" +
|
|
|
" }\n" +
|
|
|
" ],\n" +
|
|
|
" \"runtime_field_types\" : [\n" +
|
|
@@ -136,19 +182,13 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
|
|
|
@Override
|
|
|
protected MappingStats createTestInstance() {
|
|
|
- Collection<IndexFeatureStats> stats = new ArrayList<>();
|
|
|
+ Collection<FieldStats> stats = new ArrayList<>();
|
|
|
Collection<RuntimeFieldStats> runtimeFieldStats = new ArrayList<>();
|
|
|
if (randomBoolean()) {
|
|
|
- IndexFeatureStats s = new IndexFeatureStats("keyword");
|
|
|
- s.count = 10;
|
|
|
- s.indexCount = 7;
|
|
|
- stats.add(s);
|
|
|
+ stats.add(randomFieldStats("keyword"));
|
|
|
}
|
|
|
if (randomBoolean()) {
|
|
|
- IndexFeatureStats s = new IndexFeatureStats("integer");
|
|
|
- s.count = 3;
|
|
|
- s.indexCount = 3;
|
|
|
- stats.add(s);
|
|
|
+ stats.add(randomFieldStats("double"));
|
|
|
}
|
|
|
if (randomBoolean()) {
|
|
|
runtimeFieldStats.add(randomRuntimeFieldStats("keyword"));
|
|
@@ -159,17 +199,36 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
return new MappingStats(stats, runtimeFieldStats);
|
|
|
}
|
|
|
|
|
|
+ private static FieldStats randomFieldStats(String type) {
|
|
|
+ FieldStats stats = new FieldStats(type);
|
|
|
+ stats.count = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.indexCount = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ if (randomBoolean()) {
|
|
|
+ stats.scriptCount = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.scriptLangs.add(randomAlphaOfLengthBetween(3, 10));
|
|
|
+ stats.fieldScriptStats.update(
|
|
|
+ randomIntBetween(1, 100), randomLongBetween(100, 1000), randomIntBetween(1, 10), randomIntBetween(1, 10));
|
|
|
+ }
|
|
|
+ return stats;
|
|
|
+ }
|
|
|
+
|
|
|
private static RuntimeFieldStats randomRuntimeFieldStats(String type) {
|
|
|
RuntimeFieldStats stats = new RuntimeFieldStats(type);
|
|
|
+ stats.count = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.indexCount = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.scriptLessCount = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.shadowedCount = randomIntBetween(0, Integer.MAX_VALUE);
|
|
|
+ stats.scriptLangs.add(randomAlphaOfLengthBetween(3, 10));
|
|
|
if (randomBoolean()) {
|
|
|
- stats.update(randomIntBetween(1, 100), randomLongBetween(100, 1000), randomIntBetween(1, 10), randomIntBetween(1, 10));
|
|
|
+ stats.fieldScriptStats.update(
|
|
|
+ randomIntBetween(1, 100), randomLongBetween(100, 1000), randomIntBetween(1, 10), randomIntBetween(1, 10));
|
|
|
}
|
|
|
return stats;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected MappingStats mutateInstance(MappingStats instance) throws IOException {
|
|
|
- List<IndexFeatureStats> fieldTypes = new ArrayList<>(instance.getFieldTypeStats());
|
|
|
+ List<FieldStats> fieldTypes = new ArrayList<>(instance.getFieldTypeStats());
|
|
|
List<RuntimeFieldStats> runtimeFieldTypes = new ArrayList<>(instance.getRuntimeFieldStats());
|
|
|
if (randomBoolean()) {
|
|
|
boolean remove = fieldTypes.size() > 0 && randomBoolean();
|
|
@@ -177,7 +236,7 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
fieldTypes.remove(randomInt(fieldTypes.size() - 1));
|
|
|
}
|
|
|
if (remove == false || randomBoolean()) {
|
|
|
- IndexFeatureStats s = new IndexFeatureStats("float");
|
|
|
+ FieldStats s = new FieldStats("float");
|
|
|
s.count = 13;
|
|
|
s.indexCount = 2;
|
|
|
fieldTypes.add(s);
|
|
@@ -209,7 +268,7 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
.put(indexMetadata)
|
|
|
.build();
|
|
|
MappingStats mappingStats = MappingStats.of(metadata, () -> {});
|
|
|
- IndexFeatureStats expectedStats = new IndexFeatureStats("long");
|
|
|
+ FieldStats expectedStats = new FieldStats("long");
|
|
|
expectedStats.count = 1;
|
|
|
expectedStats.indexCount = 1;
|
|
|
assertEquals(
|
|
@@ -250,4 +309,32 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
|
|
|
throw new TaskCancelledException("task cancelled");
|
|
|
}));
|
|
|
}
|
|
|
+
|
|
|
+ public void testWriteToPre8_0() throws IOException {
|
|
|
+ FieldStats fieldStats = randomFieldStats("test");
|
|
|
+ MappingStats mappingStats = new MappingStats(Collections.singleton(fieldStats), Collections.emptyList());
|
|
|
+ Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
|
|
|
+ BytesStreamOutput out = new BytesStreamOutput();
|
|
|
+ out.setVersion(version);
|
|
|
+ mappingStats.writeTo(out);
|
|
|
+ StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
|
|
|
+ in.setVersion(version);
|
|
|
+ MappingStats deserialized = new MappingStats(in);
|
|
|
+ assertEquals("{\"mappings\":{\"field_types\":[" +
|
|
|
+ "{\"name\":\"test\",\"count\":" + fieldStats.count+ ",\"index_count\":" + fieldStats.indexCount +
|
|
|
+ ",\"script_count\":0}],\"runtime_field_types\":[]}}",
|
|
|
+ Strings.toString(deserialized));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testReadFromPre8_0() throws IOException {
|
|
|
+ String base64EncodedFromPre8_0 = "AQR0ZXN0qebzzQGSg/HlBgAAAAAAAAAA";
|
|
|
+ byte[] bytes = Base64.getDecoder().decode(base64EncodedFromPre8_0);
|
|
|
+ Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
|
|
|
+ StreamInput in = StreamInput.wrap(bytes);
|
|
|
+ in.setVersion(version);
|
|
|
+ MappingStats deserialized = new MappingStats(in);
|
|
|
+ assertEquals("{\"mappings\":{\"field_types\":" +
|
|
|
+ "[{\"name\":\"test\",\"count\":431813417,\"index_count\":1824276882,\"script_count\":0}],\"runtime_field_types\":[]}}",
|
|
|
+ Strings.toString(deserialized));
|
|
|
+ }
|
|
|
}
|