Upgrade string fields to text/keyword also if `ignore_above` is set. #17273
Since this parameter is used in the logstash default template, it would be nice to handle it.
This commit is contained in:
parent
b8ac05149d
commit
a3bb409f03
|
@ -192,6 +192,13 @@ public final class KeywordFieldMapper extends FieldMapper implements AllFieldMap
|
||||||
this.ignoreAbove = ignoreAbove;
|
this.ignoreAbove = ignoreAbove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Values that have more chars than the return value of this method will
|
||||||
|
* be skipped at parsing time. */
|
||||||
|
// pkg-private for testing
|
||||||
|
int ignoreAbove() {
|
||||||
|
return ignoreAbove;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KeywordFieldMapper clone() {
|
protected KeywordFieldMapper clone() {
|
||||||
return (KeywordFieldMapper) super.clone();
|
return (KeywordFieldMapper) super.clone();
|
||||||
|
|
|
@ -63,10 +63,14 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
||||||
public static final String CONTENT_TYPE = "string";
|
public static final String CONTENT_TYPE = "string";
|
||||||
private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1;
|
private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1;
|
||||||
|
|
||||||
|
// If a string field is created on 5.x and all parameters are in this list then we
|
||||||
|
// will automatically upgrade to a text/keyword field. Otherwise we will just fail
|
||||||
|
// saying that string fields are not supported anymore.
|
||||||
private static final Set<String> SUPPORTED_PARAMETERS_FOR_AUTO_UPGRADE = new HashSet<>(Arrays.asList(
|
private static final Set<String> SUPPORTED_PARAMETERS_FOR_AUTO_UPGRADE = new HashSet<>(Arrays.asList(
|
||||||
"type",
|
"type",
|
||||||
// most common parameters, for which the upgrade is straightforward
|
// most common parameters, for which the upgrade is straightforward
|
||||||
"index", "store", "doc_values", "omit_norms", "norms", "fields", "copy_to", "fielddata"));
|
"index", "store", "doc_values", "omit_norms", "norms", "fields", "copy_to",
|
||||||
|
"fielddata", "ignore_above"));
|
||||||
|
|
||||||
public static class Defaults {
|
public static class Defaults {
|
||||||
public static double FIELDDATA_MIN_FREQUENCY = 0;
|
public static double FIELDDATA_MIN_FREQUENCY = 0;
|
||||||
|
|
|
@ -151,6 +151,19 @@ public class StringMappingUpgradeTests extends ESSingleNodeTestCase {
|
||||||
assertEquals("eager_global_ordinals".equals(loading), field.fieldType().eagerGlobalOrdinals());
|
assertEquals("eager_global_ordinals".equals(loading), field.fieldType().eagerGlobalOrdinals());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUpgradeIgnoreAbove() throws IOException {
|
||||||
|
IndexService indexService = createIndex("test");
|
||||||
|
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
|
||||||
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("field").field("type", "string")
|
||||||
|
.field("index", "not_analyzed").field("ignore_above", 200).endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
|
||||||
|
FieldMapper field = mapper.mappers().getMapper("field");
|
||||||
|
assertThat(field, instanceOf(KeywordFieldMapper.class));
|
||||||
|
assertEquals(200, ((KeywordFieldMapper) field).ignoreAbove());
|
||||||
|
}
|
||||||
|
|
||||||
public void testUpgradeRandomMapping() throws IOException {
|
public void testUpgradeRandomMapping() throws IOException {
|
||||||
final int iters = 20;
|
final int iters = 20;
|
||||||
for (int i = 0; i < iters; ++i) {
|
for (int i = 0; i < iters; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue