Skip to content

Commit

Permalink
"manual" index creation and data loading (#109290)
Browse files Browse the repository at this point in the history
For "main" don't use the Lucene classes for creating and loading the
data to not trip the java security thread access permissions.
  • Loading branch information
astefan committed Jun 3, 2024
1 parent 4d1e27b commit 1e17452
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.common.CheckedBiFunction;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.LogConfigurator;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
Expand Down Expand Up @@ -195,7 +196,20 @@ public static void main(String[] args) throws IOException {

try (RestClient client = builder.build()) {
loadDataSetIntoEs(client, (restClient, indexName, indexMapping, indexSettings) -> {
ESRestTestCase.createIndex(restClient, indexName, indexSettings, indexMapping, null);
// don't use ESRestTestCase methods here or, if you do, test running the main method before making the change
StringBuilder jsonBody = new StringBuilder("{");
if (indexSettings != null && indexSettings.isEmpty() == false) {
jsonBody.append("\"settings\":");
jsonBody.append(Strings.toString(indexSettings));
jsonBody.append(",");
}
jsonBody.append("\"mappings\":");
jsonBody.append(indexMapping);
jsonBody.append("}");

Request request = new Request("PUT", "/" + indexName);
request.setJsonEntity(jsonBody.toString());
restClient.performRequest(request);
});
}
}
Expand Down

0 comments on commit 1e17452

Please sign in to comment.