lib/src/kbasesearchengine/search/ElasticIndexingStorage.java
@Override
    public void indexObjects(
            final ObjectTypeParsingRules rule,
            final SourceData data,
            final Instant timestamp, 
            final String parentJsonValue,
            final GUID pguid,
            final Map<GUID, ParsedObject> idToObj,
            final boolean isPublic)
            throws IOException, IndexingConflictException {
        if (rule.getSubObjectType().isPresent() && idToObj.isEmpty()) {
            return; // nothing to index. Only parent objects should get general records (see below)
        }
        final Map<GUID, ParsedObject> idToObjCopy = new HashMap<>(idToObj);
        String indexName = checkIndex(rule, false);
        for (GUID id : idToObjCopy.keySet()) {
            GUID parentGuid = new GUID(id.getStorageCode(), id.getAccessGroupId(), 
                    id.getAccessGroupObjectId(), id.getVersion(), null, null);
            if (!parentGuid.equals(pguid)) {
                //TODO CODE make this something that the worker error handling can work with
                throw new IllegalStateException("Object GUID doesn't match parent GUID");
            }
        }
        //TODO CODE if there's only a few objects to index, possible speed up by not using tempfile and just making direct API calls
        File tempFile = File.createTempFile("es_bulk_", ".json", tempDir);
        try {
            PrintWriter pw = new PrintWriter(tempFile);
            int lastVersion = loadLastVersion(indexName, pguid, pguid.getVersion());
            final String esParentId = checkParentDoc(indexName, new LinkedHashSet<>(
                    Arrays.asList(pguid)), isPublic, lastVersion).get(pguid);
            if (idToObjCopy.isEmpty()) { 
                // there were no search objects parsed from the source object, so just index
                // the general object information
                idToObjCopy.put(pguid, null);
            }

            for (GUID id : idToObjCopy.keySet()) {
                final ParsedObject obj = idToObjCopy.get(id);
                final Map<String, Object> doc = convertObject(id, rule.getGlobalObjectType(), obj,
                        data, timestamp, parentJsonValue, isPublic, lastVersion);
                final Map<String, Object> index = new HashMap<>();
                index.put("_index", indexName);
                index.put("_type", getDataTableName());
                index.put("parent", esParentId);
                index.put("_id", id.getURLEncoded());

                final Map<String, Object> header = ImmutableMap.of("index", index);
                pw.println(UObject.transformObjectToString(header));
                pw.println(UObject.transformObjectToString(doc));
            }
            pw.close();
            Response response = makeRequestBulk("POST", indexName, tempFile);

            verify(response);

            updateLastVersionsInData(indexName, pguid, lastVersion);
        } finally {
            tempFile.delete();
        }
    }
// IO exceptions are thrown for failure on creating or writing to file or contacting ES.
IO exceptions are thrown for failure on creating or writing to file or contacting ES.
IO exceptions are thrown for failure on creating or writing to file or contacting ES .
@Override
    public void indexObjects(
            final ObjectTypeParsingRules rule,
            final SourceData data,
            final Instant timestamp, 
            final String parentJsonValue,
            final GUID pguid,
            final Map<GUID, ParsedObject> idToObj,
            final boolean isPublic)
            throws IOException, IndexingConflictException {
        if (rule.getSubObjectType().isPresent() && idToObj.isEmpty()) {
            return; 
        }
        final Map<GUID, ParsedObject> idToObjCopy = new HashMap<>(idToObj);
        String indexName = checkIndex(rule, false);
        for (GUID id : idToObjCopy.keySet()) {
            GUID parentGuid = new GUID(id.getStorageCode(), id.getAccessGroupId(), 
                    id.getAccessGroupObjectId(), id.getVersion(), null, null);
            if (!parentGuid.equals(pguid)) {
                throw new IllegalStateException("Object GUID doesn't match parent GUID");
            }
        }
        File tempFile = File.createTempFile("es_bulk_", ".json", tempDir);
        try {
            PrintWriter pw = new PrintWriter(tempFile);
            int lastVersion = loadLastVersion(indexName, pguid, pguid.getVersion());
            final String esParentId = checkParentDoc(indexName, new LinkedHashSet<>(
                    Arrays.asList(pguid)), isPublic, lastVersion).get(pguid);
            if (idToObjCopy.isEmpty()) { 
                idToObjCopy.put(pguid, null);
            }
            for (GUID id : idToObjCopy.keySet()) {
                final ParsedObject obj = idToObjCopy.get(id);
                final Map<String, Object> doc = convertObject(id, rule.getGlobalObjectType(), obj,
                        data, timestamp, parentJsonValue, isPublic, lastVersion);
                final Map<String, Object> index = new HashMap<>();
                index.put("_index", indexName);
                index.put("_type", getDataTableName());
                index.put("parent", esParentId);
                index.put("_id", id.getURLEncoded());
                final Map<String, Object> header = ImmutableMap.of("index", index);
                pw.println(UObject.transformObjectToString(header));
                pw.println(UObject.transformObjectToString(doc));
            }
            pw.close();
            Response response = makeRequestBulk("POST", indexName, tempFile);
            verify(response);
            updateLastVersionsInData(indexName, pguid, lastVersion);
        } finally {
            tempFile.delete();
        }
    }
@ Override public void indexObjects ( final ObjectTypeParsingRules rule , final SourceData data , final Instant timestamp , final String parentJsonValue , final GUID pguid , final Map < GUID , ParsedObject > idToObj , final boolean isPublic ) throws IOException , IndexingConflictException { if ( rule . getSubObjectType ( ) . isPresent ( ) && idToObj . isEmpty ( ) ) { return ; } final Map < GUID , ParsedObject > idToObjCopy = new HashMap < > ( idToObj ) ; String indexName = checkIndex ( rule , false ) ; for ( GUID id : idToObjCopy . keySet ( ) ) { GUID parentGuid = new GUID ( id . getStorageCode ( ) , id . getAccessGroupId ( ) , id . getAccessGroupObjectId ( ) , id . getVersion ( ) , null , null ) ; if ( ! parentGuid . equals ( pguid ) ) { throw new IllegalStateException ( "Object GUID doesn't match parent GUID" ) ; } } File tempFile = File . createTempFile ( "es_bulk_" , ".json" , tempDir ) ; try { PrintWriter pw = new PrintWriter ( tempFile ) ; int lastVersion = loadLastVersion ( indexName , pguid , pguid . getVersion ( ) ) ; final String esParentId = checkParentDoc ( indexName , new LinkedHashSet < > ( Arrays . asList ( pguid ) ) , isPublic , lastVersion ) . get ( pguid ) ; if ( idToObjCopy . isEmpty ( ) ) { idToObjCopy . put ( pguid , null ) ; } for ( GUID id : idToObjCopy . keySet ( ) ) { final ParsedObject obj = idToObjCopy . get ( id ) ; final Map < String , Object > doc = convertObject ( id , rule . getGlobalObjectType ( ) , obj , data , timestamp , parentJsonValue , isPublic , lastVersion ) ; final Map < String , Object > index = new HashMap < > ( ) ; index . put ( "_index" , indexName ) ; index . put ( "_type" , getDataTableName ( ) ) ; index . put ( "parent" , esParentId ) ; index . put ( "_id" , id . getURLEncoded ( ) ) ; final Map < String , Object > header = ImmutableMap . of ( "index" , index ) ; pw . println ( UObject . transformObjectToString ( header ) ) ; pw . println ( UObject . transformObjectToString ( doc ) ) ; } pw . close ( ) ; Response response = makeRequestBulk ( "POST" , indexName , tempFile ) ; verify ( response ) ; updateLastVersionsInData ( indexName , pguid , lastVersion ) ; } finally { tempFile . delete ( ) ; } }
IO exceptions are thrown for failure on creating or writing to file or contacting ES.
IO exceptions are thrown for failure on creating or writing to file or contacting ES .
// nothing to index. Only parent objects should get general records (see below) //TODO CODE make this something that the worker error handling can work with //TODO CODE if there's only a few objects to index, possible speed up by not using tempfile and just making direct API calls // there were no search objects parsed from the source object, so just index // the general object information