Hi,
I am indexing some data and trying to fetch out using JDBCDataSource connection.
ES server version: 6.2.4 ( Docker container)
ES elasticsearch.plugin: 6.3.0
ES rest-high-level-client: 6.3.2
Getting an error:
java.sql.SQLException: Server sent bad type [illegal_argument_exception]. Original type was [request [/_xpack/sql] contains unrecognized parameter: [mode]]. [java.lang.IllegalArgumentException: request [/_xpack/sql] contains unrecognized parameter: [mode]
at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:92)...
public void testBlogSolution() throws IOException, SQLException {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost", 9200, "http"))
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(5000)
.setSocketTimeout(100000);
}
})
.setMaxRetryTimeoutMillis(100000)
);
String jsonObject = "{\"age\":10,\"dateOfBirth\":1471466076564,"
+"\"fullName\":\"John Doe\"}";
Map<String,String> map = new HashMap<String, String>();
map.put("name","ajay");
map.put("salary","12000");
map.put("teamname","development");
String str = "{"age":10,"dateOfBirth":1471466076564,"
+""fullName":"John Doe"}";
IndexRequest indexRequest = new IndexRequest("nindex", "nitesh");
indexRequest.source(str, XContentType.JSON);
IndexResponse indexResponse = client.index(indexRequest);
System.out.println(indexResponse.getIndex());
//Fetching data
JdbcDataSource dataSource = new JdbcDataSource();
String address = "jdbc:es://" + "localhost:9200";
dataSource.setUrl(address);
Properties connectionProperties = new Properties();
Connection connection = DriverManager.getConnection(address, connectionProperties);
//Properties properties = new Properties();
//properties.put("user", "test_admin");
//properties.put("password", "x-pack-test-password");
try {
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(
"");
System.out.println(results.getString(1));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}