[
https://issues.apache.org/jira/browse/CALCITE-4180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17180273#comment-17180273
]
Rui Wang commented on CALCITE-4180:
-----------------------------------
I checked the elastic search adapter implementation, I am guessing your will
need to put your user/passowrd into the host key
{code:java}
try {
List<HttpHost> hosts;
if (map.containsKey("hosts")) {
final List<String> configHosts = mapper.readValue((String)
map.get("hosts"),
new TypeReference<List<String>>() { });
hosts = configHosts
.stream()
.map(host -> HttpHost.create(host))
.collect(Collectors.toList());
} else if (map.containsKey("coordinates")) {
final Map<String, Integer> coordinates = mapper.readValue((String)
map.get("coordinates"),
new TypeReference<Map<String, Integer>>() { });
hosts = coordinates
.entrySet()
.stream()
.map(entry -> new HttpHost(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
LOGGER.warn("Prefer using hosts, coordinates is deprecated.");
} else {
throw new IllegalArgumentException
("Both 'coordinates' and 'hosts' is missing in configuration. Provide
one of them.");
}
final String pathPrefix = (String) map.get("pathPrefix");
// create client
final RestClient client = connect(hosts, pathPrefix);
final String index = (String) map.get("index");
return new ElasticsearchSchema(client, new ObjectMapper(), index);
} catch (IOException e) {
throw new RuntimeException("Cannot parse values from json", e);
}
{code}
> Where to set elasticsearch username/password?
> ---------------------------------------------
>
> Key: CALCITE-4180
> URL: https://issues.apache.org/jira/browse/CALCITE-4180
> Project: Calcite
> Issue Type: Bug
> Components: elasticsearch-adapter
> Reporter: fa
> Priority: Major
>
>
> {code:java}
> Properties config = new Properties();
> config.put("lex", "JAVA");
> String sql = "select * from index";
> try (Connection con =
> DriverManager.getConnection("jdbc:calcite:model=src/main/resources/es.json",
> config)) {
> try (Statement stmt = con.createStatement()) {
> try (ResultSet rs = stmt.executeQuery(sql)) {
> printRs(rs);
> }
> }
> }
> {code}
>
>
> es.json
> {code:java}
> {
> "version": "1.0",
> "defaultSchema": "elasticsearch",
> "schemas": [
> {
> "type": "custom",
> "name": "elasticsearch",
> "factory":
> "org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory",
> "operand": {
> "coordinates": "{'192.168.133.104': 9200}",
> "jdbcUser": "elastic",
> "jdbcPassword": "elastic"
> }
> }
> ]
> }
> {code}
> and throw Exception
> {code:java}
> {
> "error":{
> "root_cause":[
> {
> "type":"security_exception",
> "reason":"missing authentication token for REST request
> [/_alias]",
> "header":{
> "WWW-Authenticate":"Basic realm="security"
> charset="UTF-8""
> }
> }
> ],
> "type":"security_exception",
> "reason":"missing authentication token for REST request [/_alias]",
> "header":{
> "WWW-Authenticate":"Basic realm="security" charset="UTF-8""
> }
> },
> "status":401
> }
> {code}
> Where to set Elasticsearch username/password?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)