@Override protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { if (!fieldType.indexed() && !fieldType.stored()) { return; } fields.add(new Field(names.indexName(), context.type(), fieldType)); if (hasDocValues()) { fields.add(new SortedSetDocValuesField(names.indexName(), new BytesRef(context.type()))); } }
@Override protected Field parseCreateField(ParseContext context) throws IOException { // so, caching uid stream and field is fine // since we don't do any mapping parsing without immediate indexing // and, when percolating, we don't index the uid UidField field = fieldCache.get(); field.setUid(Uid.createUid(context.stringBuilder(), context.type(), context.id())); context.uid(field); return field; // version get updated by the engine }
@Override protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { boolean parent = context.docMapper().isParent(context.type()); if (parent) { addJoinFieldIfNeeded(fields, parentJoinFieldType, context.id()); } if (!active()) { return; } if (context.parser().currentName() != null && context.parser().currentName().equals(Defaults.NAME)) { // we are in the parsing of _parent phase String parentId = context.parser().text(); context.sourceToParse().parent(parentId); fields.add( new Field( fieldType().name(), Uid.createUid(context.stringBuilder(), parentType, parentId), fieldType())); addJoinFieldIfNeeded(fields, childJoinFieldType, parentId); } else { // otherwise, we are running it post processing of the xcontent String parsedParentId = context.doc().get(Defaults.NAME); if (context.sourceToParse().parent() != null) { String parentId = context.sourceToParse().parent(); if (parsedParentId == null) { if (parentId == null) { throw new MapperParsingException( "No parent id provided, not within the document, and not externally"); } // we did not add it in the parsing phase, add it now fields.add( new Field( fieldType().name(), Uid.createUid(context.stringBuilder(), parentType, parentId), fieldType())); addJoinFieldIfNeeded(fields, childJoinFieldType, parentId); } else if (parentId != null && !parsedParentId.equals( Uid.createUid(context.stringBuilder(), parentType, parentId))) { throw new MapperParsingException( "Parent id mismatch, document value is [" + Uid.createUid(parsedParentId).id() + "], while external value is [" + parentId + "]"); } } } // we have parent mapping, yet no value was set, ignore it... }
@Override protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException { Field uid = new Field( NAME, Uid.createUid(context.stringBuilder(), context.type(), context.id()), Defaults.FIELD_TYPE); context.uid(uid); fields.add(uid); if (fieldType().hasDocValues()) { fields.add(new BinaryDocValuesField(NAME, new BytesRef(uid.stringValue()))); } }
@Override protected void innerParseCreateField(ParseContext context, List<Field> fields) throws IOException, AlreadyExpiredException { if (enabledState.enabled && !context.sourceToParse().flyweight()) { long ttl = context.sourceToParse().ttl(); if (ttl <= 0 && defaultTTL > 0) { // no ttl provided so we use the default value ttl = defaultTTL; context.sourceToParse().ttl(ttl); } if (ttl > 0) { // a ttl has been provided either externally or in the _source long timestamp = context.sourceToParse().timestamp(); long expire = new Date(timestamp + ttl).getTime(); long now = System.currentTimeMillis(); // there is not point indexing already expired doc if (context.sourceToParse().origin() == SourceToParse.Origin.PRIMARY && now >= expire) { throw new AlreadyExpiredException( context.index(), context.type(), context.id(), timestamp, ttl, now); } // the expiration timestamp (timestamp + ttl) is set as field fields.add(new CustomLongNumericField(this, expire, (NumberFieldType) fieldType)); } } }