private ParsedDocument parseDocument(String index, String type, BytesReference doc) {
    MapperService mapperService = indexShard.mapperService();
    IndexService indexService = indexShard.indexService();

    // TODO: make parsing not dynamically create fields not in the original mapping
    Tuple<DocumentMapper, Boolean> docMapper = mapperService.documentMapperWithAutoCreate(type);
    ParsedDocument parsedDocument =
        docMapper.v1().parse(source(doc).type(type).flyweight(true)).setMappingsModified(docMapper);
    if (parsedDocument.mappingsModified()) {
      mappingUpdatedAction.updateMappingOnMaster(index, docMapper.v1(), indexService.indexUUID());
    }
    return parsedDocument;
  }
 private Analyzer getAnalyzerAtField(
     String field, @Nullable Map<String, String> perFieldAnalyzer) {
   MapperService mapperService = indexShard.mapperService();
   Analyzer analyzer;
   if (perFieldAnalyzer != null && perFieldAnalyzer.containsKey(field)) {
     analyzer = mapperService.analysisService().analyzer(perFieldAnalyzer.get(field).toString());
   } else {
     analyzer = mapperService.smartNameFieldMapper(field).indexAnalyzer();
   }
   if (analyzer == null) {
     analyzer = mapperService.analysisService().defaultIndexAnalyzer();
   }
   return analyzer;
 }