diff --git a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java index 0ad3072fe1cb..6657a3079084 100644 --- a/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java +++ b/core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java @@ -38,6 +38,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.RecoverySource; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -55,6 +56,8 @@ import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHitField; +import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.terms.Terms; @@ -242,6 +245,7 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase { assertUpgradeWorks(client(), indexName, version); assertPositionIncrementGapDefaults(indexName, version); assertAliasWithBadName(indexName, version); + assertStoredBinaryFields(indexName, version); unloadIndex(indexName); } @@ -461,6 +465,25 @@ public class OldIndexBackwardsCompatibilityIT extends ESIntegTestCase { assertFalse(client().admin().indices().prepareAliasesExist(aliasName).get().exists()); } + /** + * Make sure we can load stored binary fields. + */ + void assertStoredBinaryFields(String indexName, Version version) throws Exception { + SearchRequestBuilder builder = client().prepareSearch(indexName); + builder.setQuery(QueryBuilders.matchAllQuery()); + builder.setSize(100); + builder.addStoredField("binary"); + SearchHits hits = builder.get().getHits(); + assertEquals(100, hits.hits().length); + for(SearchHit hit : hits) { + SearchHitField field = hit.field("binary"); + assertNotNull(field); + Object value = field.value(); + assertTrue(value instanceof BytesArray); + assertEquals(16, ((BytesArray) value).length()); + } + } + private Path getNodeDir(String indexFile) throws IOException { Path unzipDir = createTempDir(); Path unzipDataDir = unzipDir.resolve("data"); diff --git a/core/src/test/resources/indices/bwc/index-5.0.0.zip b/core/src/test/resources/indices/bwc/index-5.0.0.zip index f8deb41276b8..a04b829c2cf9 100644 Binary files a/core/src/test/resources/indices/bwc/index-5.0.0.zip and b/core/src/test/resources/indices/bwc/index-5.0.0.zip differ diff --git a/core/src/test/resources/indices/bwc/index-5.0.1.zip b/core/src/test/resources/indices/bwc/index-5.0.1.zip index 8b58866a9706..256e162fa92f 100644 Binary files a/core/src/test/resources/indices/bwc/index-5.0.1.zip and b/core/src/test/resources/indices/bwc/index-5.0.1.zip differ diff --git a/core/src/test/resources/indices/bwc/index-5.0.2.zip b/core/src/test/resources/indices/bwc/index-5.0.2.zip index 3ad5ebb8e5ec..1a85f4599ede 100644 Binary files a/core/src/test/resources/indices/bwc/index-5.0.2.zip and b/core/src/test/resources/indices/bwc/index-5.0.2.zip differ diff --git a/core/src/test/resources/indices/bwc/index-5.1.1.zip b/core/src/test/resources/indices/bwc/index-5.1.1.zip index cd88ea5e8f19..ab13e00b66e4 100644 Binary files a/core/src/test/resources/indices/bwc/index-5.1.1.zip and b/core/src/test/resources/indices/bwc/index-5.1.1.zip differ diff --git a/core/src/test/resources/indices/bwc/repo-5.0.0.zip b/core/src/test/resources/indices/bwc/repo-5.0.0.zip index e873b9bc9a80..df2878e47a80 100644 Binary files a/core/src/test/resources/indices/bwc/repo-5.0.0.zip and b/core/src/test/resources/indices/bwc/repo-5.0.0.zip differ diff --git a/core/src/test/resources/indices/bwc/repo-5.0.1.zip b/core/src/test/resources/indices/bwc/repo-5.0.1.zip index 08051b56545b..dd2484b8a405 100644 Binary files a/core/src/test/resources/indices/bwc/repo-5.0.1.zip and b/core/src/test/resources/indices/bwc/repo-5.0.1.zip differ diff --git a/core/src/test/resources/indices/bwc/repo-5.0.2.zip b/core/src/test/resources/indices/bwc/repo-5.0.2.zip index 8a7784e25f13..47ce08fcdd67 100644 Binary files a/core/src/test/resources/indices/bwc/repo-5.0.2.zip and b/core/src/test/resources/indices/bwc/repo-5.0.2.zip differ diff --git a/core/src/test/resources/indices/bwc/repo-5.1.1.zip b/core/src/test/resources/indices/bwc/repo-5.1.1.zip index 3ddf4beb5aa7..01a9645e55ec 100644 Binary files a/core/src/test/resources/indices/bwc/repo-5.1.1.zip and b/core/src/test/resources/indices/bwc/repo-5.1.1.zip differ diff --git a/dev-tools/create_bwc_index.py b/dev-tools/create_bwc_index.py index 5751335d1e3f..a6814e52f8fe 100644 --- a/dev-tools/create_bwc_index.py +++ b/dev-tools/create_bwc_index.py @@ -15,6 +15,7 @@ # language governing permissions and limitations under the License. import argparse +import base64 import glob import logging import os @@ -73,6 +74,8 @@ def index(es, index_name, type, num_docs, supports_dots_in_field_names, flush=Fa if supports_dots_in_field_names: body['field.with.dots'] = str(random.randint(0, 100)) + body['binary'] = base64.b64encode(bytearray(random.getrandbits(8) for _ in range(16))).decode('ascii') + es.index(index=index_name, doc_type=type, id=id, body=body) if rarely(): @@ -334,6 +337,12 @@ def generate_index(client, version, index_name): } }) + # test back-compat of stored binary fields + mappings['doc']['properties']['binary'] = { + 'type': 'binary', + 'store': True, + } + settings = { 'number_of_shards': 1, 'number_of_replicas': 0,