我正在使用 Apache Flink v1.6.0 并且我正在嘗試寫(xiě)入 Elasticsearch v6.4.0,它托管在Elastic Cloud 中。我在對(duì) Elastic Cloud 集群進(jìn)行身份驗(yàn)證時(shí)遇到問(wèn)題。我已經(jīng)能夠使用以下代碼讓 Flink 寫(xiě)入本地 Elasticsearch v6.4.0 節(jié)點(diǎn),該節(jié)點(diǎn)沒(méi)有加密:/* Elasticsearch Configuration*/List<HttpHost> httpHosts = new ArrayList<>();httpHosts.add(new HttpHost("127.0.0.1", 9200, "http"));// use a ElasticsearchSink.Builder to create an ElasticsearchSinkElasticsearchSink.Builder<ObjectNode> esSinkBuilder = new ElasticsearchSink.Builder<>( httpHosts, new ElasticsearchSinkFunction<ObjectNode>() { private IndexRequest createIndexRequest(ObjectNode payload) { // remove the value node so the fields are at the base of the json payload JsonNode jsonOutput = payload.get("value"); return Requests.indexRequest() .index("raw-payload") .type("payload") .source(jsonOutput.toString(), XContentType.JSON); } @Override public void process(ObjectNode payload, RuntimeContext ctx, RequestIndexer indexer) { indexer.add(createIndexRequest(payload)); } });// set number of events to be seen before writing to ElasticsearchesSinkBuilder.setBulkFlushMaxActions(1);// finally, build and add the sink to the job's pipelinestream.addSink(esSinkBuilder.build());然而,當(dāng)我嘗試添加驗(yàn)證到代碼庫(kù)中,作為記錄在這里的弗林克文檔和這里對(duì)應(yīng)Elasticsearch Java文檔上。看起來(lái)像這樣:// provide a RestClientFactory for custom configuration on the internally created REST clientHeader[] defaultHeaders = new Header[]{new BasicHeader("username", "password")};esSinkBuilder.setRestClientFactory( restClientBuilder -> { restClientBuilder.setDefaultHeaders(defaultHeaders); });誰(shuí)能幫忙指出我哪里出錯(cuò)了?
Apache Flink (v1.6.0) 驗(yàn)證 Elasticsearch Sink (v6.4)
ibeautiful
2021-09-12 15:50:38