Add stored binary fields to static backwards compatibility indices tests (#22054)

Add stored binary fields to static backwards compatibility indices tests
This commit is contained in:
Michael McCandless 2016-12-09 05:32:40 -05:00 committed by GitHub
parent 6714e02bef
commit 613a1a6a18
10 changed files with 32 additions and 0 deletions

View File

@ -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");

View File

@ -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,