Skip to content

Commit

Permalink
#141 Adding index mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Nov 16, 2024
1 parent 48e727c commit c9e78b1
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import ai.philterd.phileas.benchmarks.Documents;
import ai.philterd.phileas.benchmarks.Redactor;
import com.fasterxml.jackson.core.JsonParser;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
Expand All @@ -16,12 +18,17 @@
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.client.RestHighLevelClient;
import org.opensearch.client.indices.CreateIndexRequest;
import org.opensearch.client.indices.GetIndexRequest;
import org.opensearch.core.xcontent.MediaType;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509ExtendedTrustManager;
import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -128,6 +135,18 @@ public void runBenchmarks() throws Exception {
.setDefaultCredentialsProvider(credentialsProvider));

final RestHighLevelClient openSearchClient = new RestHighLevelClient(builder);

if(!openSearchClient.indices().exists(new GetIndexRequest("phileas_benchmarks"), RequestOptions.DEFAULT)) {

final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("mapping.json");
final String mapping = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());

final CreateIndexRequest createIndexRequest = new CreateIndexRequest("phileas_benchmarks");
createIndexRequest.mapping(mapping, MediaType.fromMediaType("application/json; charset=UTF-8"));
openSearchClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);

}

openSearchClient.bulk(bulkRequest, RequestOptions.DEFAULT);

}
Expand Down
117 changes: 117 additions & 0 deletions phileas-benchmark/src/test/resources/mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"properties": {
"branch": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"calls_per_second": {
"properties": {
"0": {
"type": "long"
},
"1": {
"type": "long"
},
"1024": {
"type": "long"
},
"128": {
"type": "long"
},
"1280": {
"type": "long"
},
"1536": {
"type": "long"
},
"16": {
"type": "long"
},
"1792": {
"type": "long"
},
"2": {
"type": "long"
},
"2048": {
"type": "long"
},
"256": {
"type": "long"
},
"3072": {
"type": "long"
},
"32": {
"type": "long"
},
"4": {
"type": "long"
},
"4096": {
"type": "long"
},
"512": {
"type": "long"
},
"64": {
"type": "long"
},
"768": {
"type": "long"
},
"8": {
"type": "long"
}
}
},
"document": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"phileas_version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"redactor": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"run_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date",
"format": "epoch_millis"
},
"workload_mills": {
"type": "long"
}
}
}

0 comments on commit c9e78b1

Please sign in to comment.