@Override protected Field parseCreateField(ParseContext context) throws IOException { 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); return new Field( names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType); } // 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 return new Field( names.indexName(), Uid.createUid(context.stringBuilder(), type, parentId), fieldType); } else if (parentId != null && !parsedParentId.equals(Uid.createUid(context.stringBuilder(), type, 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... return null; }
@Override public Uid value(Object value) { if (value == null) { return null; } return Uid.createUid(value.toString()); }
@Override public void stringField(FieldInfo fieldInfo, String value) throws IOException { if (UidFieldMapper.NAME.equals(fieldInfo.name)) { uid = Uid.createUid(value); } else { addValue(fieldInfo.name, value); } }
@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 public void collect(int doc) throws IOException { // the _source is the query Document document = reader.document(doc, new UidAndSourceFieldSelector()); String id = Uid.createUid(document.get(UidFieldMapper.NAME)).id(); byte[] source = document.getBinaryValue(SourceFieldMapper.NAME); try { queries.put(id, percolator.parseQuery(id, source, 0, source.length)); } catch (Exception e) { logger.warn("failed to add query [{}]", e, id); } }
public Term term(String type, String id) { return term(Uid.createUid(type, id)); }
@Override public Uid valueFromString(String value) { return Uid.createUid(value); }
@Override public Uid value(Object value) { return Uid.createUid(String.valueOf(value)); }