Skip to content

Commit

Permalink
Mappings: Allow to force dots in field names
Browse files Browse the repository at this point in the history
With the changes in 5.0 to allow dots in field names for documents as
well as mappings, we now have the possibility to allow a path forward
for users which must have dots in fields on 2.x. This change adds an
option to override the dot checks, `mapper.allow_dots_in_name` which may
be set to `true` to omit the dots in field names error check. The
resulting mappings will contain dots in the field names, and on upgrade
to 5.x, those will be automatically converted to object mappings on
startup.

Note that this works because the underlying lucene indexes uses the full
path. If a user users this to produce corrupt mappings, for example, two
fields `foo` and `foo.bar` which are both text, the upgrade to 5.x will
fail (because `foo` cannot be an object as well as a string field).
  • Loading branch information
rjernst committed Aug 11, 2016
1 parent 76d5af9 commit 266bd52
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.CopyOnWriteHashMap;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class ObjectMapper extends Mapper implements AllFieldMapper.IncludeInAll,
public static final String CONTENT_TYPE = "object";
public static final String NESTED_CONTENT_TYPE = "nested";

private static final boolean DOTS_IN_FIELD_ALLOWED = Booleans.parseBooleanExact(
System.getProperty("mapper.allow_dots_in_name", "false"));

public static class Defaults {
public static final boolean ENABLED = true;
public static final Nested NESTED = Nested.NO;
Expand Down Expand Up @@ -269,7 +273,7 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map<Strin
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String fieldName = entry.getKey();
if (fieldName.contains(".")) {
if (fieldName.contains(".") && DOTS_IN_FIELD_ALLOWED == false) {
throw new MapperParsingException("Field name [" + fieldName + "] cannot contain '.'");
}
// Should accept empty arrays, as a work around for when the
Expand Down

0 comments on commit 266bd52

Please sign in to comment.