{"record":{"id":"4f1b71880b03693d","repo":"NationalSecurityAgency/ghidra","slug":"database-instance-does-not-exist","errorCode":null,"errorMessage":"Database instance does not exist","messagePattern":"Database instance does not exist","errorType":"exception","errorClass":"NoDatabaseException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java","lineNumber":2104,"sourceCode":"\t}\n\n\t/**\n\t * Read database configuration (\"keyvalue\" documents) into a key/value pair map.\n\t * @return the populated map\n\t * @throws ElasticException for communication problems with the server\n\t * @throws NoDatabaseException if the database (as opposed to the server) does not exist\n\t */\n\tprivate Map<String, String> readKeyValues() throws ElasticException, NoDatabaseException {\n\t\tStringBuilder buffer = new StringBuilder();\n\t\tbuffer.append(\"{ \\\"size\\\": 500, \\\"query\\\": { \\\"match_all\\\": {} } }\");\n\t\tJsonObject resp;\n\t\ttry {\n\t\t\tresp = connection.executeStatement(ElasticConnection.GET, \"configuration/_search\",\n\t\t\t\tbuffer.toString());\n\t\t}\n\t\tcatch (ElasticException ex) {\n\t\t\tif (ex.getMessage().contains(\"index_not_found_exception\")) {\n\t\t\t\tthrow new NoDatabaseException(\"Database instance does not exist\");\n\t\t\t}\n\t\t\tthrow ex;\n\t\t}\n\t\tJsonObject baseHits = (JsonObject) resp.get(\"hits\");\n\t\tlong total = 0;\n\t\tif (baseHits != null) {\n\t\t\tJsonObject totalRec = (JsonObject) baseHits.get(\"total\");\n\t\t\ttotal = totalRec.get(\"value\").getAsLong();\n\t\t}\n\t\tif (total <= 1) {\n\t\t\tthrow new ElasticException(\"Unrecoverable error: Could not find configuration\");\n\t\t}\n\t\tHashMap<String, String> res = new HashMap<>();\n\t\tJsonArray hits = (JsonArray) baseHits.get(\"hits\");\n\t\tfor (JsonElement hit2 : hits) {\n\t\t\tJsonObject hit = (JsonObject) hit2;\n\t\t\tString key = hit.get(\"_id\").getAsString();\n\t\t\tJsonObject source = (JsonObject) hit.get(\"_source\");","sourceCodeStart":2086,"sourceCodeEnd":2122,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java#L2086-L2122","documentation":"Thrown as a NoDatabaseException in readKeyValues when the configuration/_search GET request fails and the ElasticException message contains \"index_not_found_exception\". This means the repository's configuration index does not exist on the Elasticsearch server — the database has never been created via the generate/create command.","triggerScenarios":"During initialize(), readKeyValues queries configuration/_search. If the Elasticsearch server responds with an index_not_found_exception for the configuration index, the catch block converts it to NoDatabaseException. This is caught by initialize() which sets status to Error and lastError to a Nodatabase category.","commonSituations":"First-time connection to a new Elasticsearch server before running generate; typo in the repository name in the URL; the database was dropped; connecting to the wrong server or port.","solutions":["Create the database first using the BSim generate/create command with the same URL and repository name.","Verify the repository name in the connection URL matches an existing repository on the server.","Confirm you are connecting to the correct Elasticsearch server and port.","Check the initialize() return value and lastError to distinguish NoDatabase from other initialization failures."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check if the database exists before initializing\ntry {\n    connection.executeURIOnly(ElasticConnection.GET, \"configuration/_search\");\n} catch (ElasticException e) {\n    if (e.getMessage().contains(\"index_not_found_exception\")) {\n        // Database does not exist — prompt user to create it\n        Msg.warn(this, \"Database does not exist. Run 'bsim generate' first.\");\n        return;\n    }\n}","typeGuard":null,"tryCatchPattern":"if (!database.initialize()) {\n    BSimError err = database.getLastError();\n    if (err != null && err.category == ErrorCategory.Nodatabase) {\n        Msg.warn(this, \"Database not created yet: \" + err.message);\n        // Prompt user to run generate/create\n    }\n}","preventionTips":["Run the generate/create command before connecting to a new repository.","Check the initialize() return value and lastError category to distinguish missing-database from other failures.","Verify the repository name in the URL matches an existing repository on the server."],"tags":["elasticsearch","bsim","initialization","missing-database","configuration","index-not-found"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}