GP-5207 Corrected various bugs related to BSim Elasticsearch

This commit is contained in:
ghidra1
2024-12-19 09:39:54 -05:00
parent c405ce78e5
commit 30a77f9aa4
2 changed files with 13 additions and 6 deletions
@@ -206,8 +206,14 @@ public class CreateBsimServerInfoDialog extends DialogComponentProvider {
nameField = new NotifyingTextField(); nameField = new NotifyingTextField();
hostField = new NotifyingTextField(); hostField = new NotifyingTextField();
portField = int defaultPort = -1;
new NotifyingTextField(Integer.toString(BSimServerInfo.DEFAULT_POSTGRES_PORT)); if (type == BSimServerInfo.DBType.postgres) {
defaultPort = BSimServerInfo.DEFAULT_POSTGRES_PORT;
}
else if (type == BSimServerInfo.DBType.elastic) {
defaultPort = BSimServerInfo.DEFAULT_ELASTIC_PORT;
}
portField = new NotifyingTextField(Integer.toString(defaultPort));
JLabel nameLabel = new JLabel("DB Name:", SwingConstants.RIGHT); JLabel nameLabel = new JLabel("DB Name:", SwingConstants.RIGHT);
JLabel hostLabel = new JLabel("Host:", SwingConstants.RIGHT); JLabel hostLabel = new JLabel("Host:", SwingConstants.RIGHT);
@@ -1144,6 +1144,7 @@ public class ElasticDatabase implements FunctionDatabase {
String exeId, DescriptionManager manager, int maxDocuments) throws ElasticException { String exeId, DescriptionManager manager, int maxDocuments) throws ElasticException {
long total; long total;
long start = 0; long start = 0;
long count = 0;
do { do {
int limit = MAX_FUNCTION_WINDOW; int limit = MAX_FUNCTION_WINDOW;
if (maxDocuments != 0 && maxDocuments - start < limit) { if (maxDocuments != 0 && maxDocuments - start < limit) {
@@ -1162,6 +1163,7 @@ public class ElasticDatabase implements FunctionDatabase {
doc = (JSONObject) element; doc = (JSONObject) element;
FunctionDescription funcDesc = convertDescriptionRow(doc, exeRecord, manager, null); FunctionDescription funcDesc = convertDescriptionRow(doc, exeRecord, manager, null);
listFunctions.add(funcDesc); listFunctions.add(funcDesc);
++count;
} }
if (hitsarray.size() == 0) { if (hitsarray.size() == 0) {
break; // Shouldn't need this, but just in case break; // Shouldn't need this, but just in case
@@ -1169,7 +1171,7 @@ public class ElasticDatabase implements FunctionDatabase {
JSONArray sort = (JSONArray) doc.get("sort"); JSONArray sort = (JSONArray) doc.get("sort");
start = (Long) sort.get(0); // Sort value for last entry, for passing as search_after parameter start = (Long) sort.get(0); // Sort value for last entry, for passing as search_after parameter
} }
while (total > start); while (total > count);
return (int) total; return (int) total;
} }
@@ -1766,7 +1768,6 @@ public class ElasticDatabase implements FunctionDatabase {
buffer.append( buffer.append(
"{ \"script\": { \"inline\": \"if ((ctx._source.count -= params.count) <=0) { ctx.op = \\\"delete\\\" }\", "); "{ \"script\": { \"inline\": \"if ((ctx._source.count -= params.count) <=0) { ctx.op = \\\"delete\\\" }\", ");
buffer.append("\"params\": { \"count\": ").append(entry.count).append("} } }\n"); buffer.append("\"params\": { \"count\": ").append(entry.count).append("} } }\n");
maxVectors -= 1;
} }
JSONObject resp = connection.executeBulk("/_bulk", buffer.toString()); JSONObject resp = connection.executeBulk("/_bulk", buffer.toString());
JSONArray items = (JSONArray) resp.get("items"); JSONArray items = (JSONArray) resp.get("items");