@Override
  protected void doMerge(Mapper mergeWith, boolean updateAllTypes) {
    super.doMerge(mergeWith, updateAllTypes);
    ParentFieldMapper fieldMergeWith = (ParentFieldMapper) mergeWith;
    if (Objects.equals(parentType, fieldMergeWith.parentType) == false) {
      throw new IllegalArgumentException(
          "The _parent field's type option can't be changed: ["
              + parentType
              + "]->["
              + fieldMergeWith.parentType
              + "]");
    }

    List<String> conflicts = new ArrayList<>();
    fieldType()
        .checkCompatibility(
            fieldMergeWith.fieldType(), conflicts, true); // always strict, this cannot change
    parentJoinFieldType.checkCompatibility(
        fieldMergeWith.parentJoinFieldType, conflicts, true); // same here
    if (childJoinFieldType != null) {
      // TODO: this can be set to false when the old parent/child impl is removed, we can do eager
      // global ordinals loading per type.
      childJoinFieldType.checkCompatibility(
          fieldMergeWith.childJoinFieldType, conflicts, updateAllTypes == false);
    }
    if (conflicts.isEmpty() == false) {
      throw new IllegalArgumentException("Merge conflicts: " + conflicts);
    }

    if (active()) {
      childJoinFieldType = fieldMergeWith.childJoinFieldType.clone();
    }
  }
예제 #2
0
 @Override
 public void preParse(ParseContext context) throws IOException {
   if (context.sourceToParse().id() != null) {
     context.id(context.sourceToParse().id());
     super.parse(context);
   }
 }
예제 #3
0
 @Override
 public void preParse(ParseContext context) throws IOException {
   // if we have the id provided, fill it, and parse now
   if (context.sourceToParse().id() != null) {
     context.id(context.sourceToParse().id());
     super.parse(context);
   }
 }
  @Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (pre13Index) {
      return builder;
    }
    boolean includeDefaults = params.paramAsBoolean("include_defaults", false);

    if (includeDefaults == false && fieldType().isEnabled() == Defaults.ENABLED) {
      return builder;
    }

    builder.startObject(NAME);
    if (includeDefaults || fieldType().isEnabled() != Defaults.ENABLED) {
      builder.field("enabled", fieldType().isEnabled());
    }
    if (indexCreatedBefore2x
        && (includeDefaults || fieldType().equals(Defaults.FIELD_TYPE) == false)) {
      super.doXContentBody(builder, includeDefaults, params);
    }

    builder.endObject();
    return builder;
  }
예제 #5
0
 @Override
 public void postParse(ParseContext context) throws IOException {
   if (context.id() == null && !context.sourceToParse().flyweight()) {
     throw new MapperParsingException("No id found while parsing the content source");
   }
   // if we did not have the id as part of the sourceToParse, then we need to parse it here
   // it would have been filled in the _id parse phase
   if (context.sourceToParse().id() == null) {
     super.parse(context);
     // since we did not have the uid in the pre phase, we did not add it automatically to the
     // nested docs
     // as they were created we need to make sure we add it to all the nested docs...
     if (context.docs().size() > 1) {
       final IndexableField uidField = context.rootDoc().getField(UidFieldMapper.NAME);
       assert uidField != null;
       // we need to go over the docs and add it...
       for (int i = 1; i < context.docs().size(); i++) {
         final Document doc = context.docs().get(i);
         doc.add(
             new Field(UidFieldMapper.NAME, uidField.stringValue(), Defaults.NESTED_FIELD_TYPE));
       }
     }
   }
 }
 @Override
 public void postParse(ParseContext context) throws IOException {
   super.parse(context);
 }
 @Override
 public void postParse(ParseContext context) throws IOException {
   // we post parse it so we get the size stored, possibly compressed (source will be preParse)
   super.parse(context);
 }