Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将Apache Flink连接到elasticsearch的问题_Java_Maven_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Netbeans_Apache Flink - Fatal编程技术网 elasticsearch,netbeans,apache-flink,Java,Maven,elasticsearch,Netbeans,Apache Flink" /> elasticsearch,netbeans,apache-flink,Java,Maven,elasticsearch,Netbeans,Apache Flink" />

Java 将Apache Flink连接到elasticsearch的问题

Java 将Apache Flink连接到elasticsearch的问题,java,maven,elasticsearch,netbeans,apache-flink,Java,Maven,elasticsearch,Netbeans,Apache Flink,我在Flink站点中使用了一段代码将ApacheFlink连接到ElasticSearch。我想通过maven项目从NetBeans软件运行这段代码 public class FlinkElasticCon { public static void main(String[] args) throws Exception { final int port; try { final ParameterTool params = ParameterTool.fr

我在Flink站点中使用了一段代码将ApacheFlink连接到ElasticSearch。我想通过maven项目从NetBeans软件运行这段代码

public class FlinkElasticCon {

 public static void main(String[] args) throws Exception {

    final int port;
    try {
        final ParameterTool params = ParameterTool.fromArgs(args);
        port = params.getInt("port");
    } catch (Exception e) {
        System.err.println("No port specified. Please run 'SocketWindowWordCount --port <port>'");
        return;
    }

    // get the execution environment
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    // get input data by connecting to the socket
    DataStream<String> text = env.socketTextStream("localhost", port, "\n");

    // parse the data, group it, window it, and aggregate the counts
    DataStream<WordWithCount> windowCounts = text

        .flatMap((String value, Collector<WordWithCount> out) -> {
            for (String word : value.split("\\s")) {
                out.collect(new WordWithCount(word, 1L));
            }
    })

       .keyBy("word")
        .timeWindow(Time.seconds(5))

        .reduce(new ReduceFunction<WordWithCount>() {
            @Override
            public WordWithCount reduce(WordWithCount a, WordWithCount b) {
                return new WordWithCount(a.word, a.count + b.count);
            }
        });

    // print the results with a single thread, rather than in parallel
    //windowCounts.print().setParallelism(1);

    env.execute("Socket Window WordCount");


    List<HttpHost> httpHosts = new ArrayList<>();
    httpHosts.add(new HttpHost("127.0.0.1", 9200, "http"));
    httpHosts.add(new HttpHost("10.2.3.1", 9200, "http"));       

    ElasticsearchSink.Builder<String> esSinkBuilder = new ElasticsearchSink.Builder<>(
        httpHosts,
        new ElasticsearchSinkFunction<String>() {
            public IndexRequest createIndexRequest(String element) {
                Map<String, String> json = new HashMap<>();
                json.put("data", element);

                return Requests
                        .indexRequest()
                        .index("my-index")
                        .type("my-type")
                        .source(json);
            }

            @Override
            public void process(String element, RuntimeContext ctx, RequestIndexer indexer) {
                indexer.add(createIndexRequest(element));
            }
        }
    );


    windowCounts.addSink((SinkFunction<WordWithCount>) esSinkBuilder);

}

     public static class WordWithCount {

    public String word;
    public long count;

    public WordWithCount() {}

    public WordWithCount(String word, long count) {
        this.word = word;
        this.count = count;
    }

    @Override
    public String toString() {
        return word + " : " + count;
    }
}
}
红线在代码中被创建为未知

我的pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.flink</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>

    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-connector-elasticsearch6_2.11</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-java_2.11</artifactId>
        <version>1.8.1</version>
         <scope>provided</scope>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-connector-elasticsearch-base_2.11</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.0.0-alpha1</version>
        <!--<version>6.0.0-alpha1</version>-->
        <type>jar</type>
    </dependency>




        <dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-java</artifactId>
    <version>1.8.1</version>
              <type>jar</type>
        </dependency>

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients_2.11</artifactId>
    <version>1.8.1</version>
</dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-core</artifactId>
        <version>0.8.1</version>
    </dependency>
</dependencies>



<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

</properties>

4.0.0
org.apache.flink
mavenproject1
1.0-快照
罐子
org.apache.flink
flink-connector-elasticsearch6_2.11
1.8.1
org.apache.flink
flink-streaming-java_2.11
1.8.1
假如
罐子
org.apache.flink
flink-connector-elasticsearch-base_2.11
1.8.1
org.elasticsearch
弹性搜索
6.0.0-1
罐子
org.apache.flink
弗林克爪哇
1.8.1
罐子
org.apache.flink
flink-U 2.11
1.8.1
org.apache.flink
弗林克流芯
0.8.1
UTF-8
1.8
1.8

ApacheFlink版本:1.8.1 elasticsearch版本:7.4.2 netbeans版本:8.2 java版本:8

请帮帮我。

Flink Elasticsearch接头7

请找到一个工作和详细的答案,我已经提供

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.flink</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>

    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-connector-elasticsearch6_2.11</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-java_2.11</artifactId>
        <version>1.8.1</version>
         <scope>provided</scope>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-connector-elasticsearch-base_2.11</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.0.0-alpha1</version>
        <!--<version>6.0.0-alpha1</version>-->
        <type>jar</type>
    </dependency>




        <dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-java</artifactId>
    <version>1.8.1</version>
              <type>jar</type>
        </dependency>

<dependency>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-clients_2.11</artifactId>
    <version>1.8.1</version>
</dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-core</artifactId>
        <version>0.8.1</version>
    </dependency>
</dependencies>



<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

</properties>