当前位置: 首页 > news >正文

供求信息网站开发背景seo外包公司多吗

供求信息网站开发背景,seo外包公司多吗,wordpress mu插件,海口网站建设电话提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、写入到Elasticsearch5二、写入到Elasticsearch7总结 前言 Flink sink 流数据写入到es5和es7的简单示例。 一、写入到Elasticsearch5 pom maven依赖 <d…

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、写入到Elasticsearch5
  • 二、写入到Elasticsearch7
  • 总结


前言

Flink sink 流数据写入到es5和es7的简单示例。


一、写入到Elasticsearch5

  • pom maven依赖
        <dependency><groupId>org.apache.flink</groupId><artifactId>flink-connector-elasticsearch5_2.11</artifactId><version>${flink.version}</version></dependency>
  • 代码如下(示例):
public class Es5SinkDemo {public static void main(String[] args) throws Exception {StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();Row row=Row.of("张三","001",getTimestamp("2016-10-24 21:59:06"));Row row2=Row.of("张三","002",getTimestamp("2016-10-24 21:50:06"));Row row3=Row.of("张三","002",getTimestamp("2016-10-24 21:51:06"));Row row4=Row.of("李四","003",getTimestamp("2016-10-24 21:50:56"));Row row5=Row.of("李四","004",getTimestamp("2016-10-24 00:48:36"));Row row6=Row.of("王五","005",getTimestamp("2016-10-24 00:48:36"));DataStreamSource<Row> source =env.fromElements(row,row2,row3,row4,row5,row6);Map<String, String> config = new HashMap<>();
//        config.put("cluster.name", "my-cluster-name");
//        config.put("bulk.flush.max.actions", "1");List<InetSocketAddress> transportAddresses = new ArrayList<>();transportAddresses.add(new InetSocketAddress(InetAddress.getByName("10.68.8.60"), 9300));//Sink操作DataStreamSink<Row> rowDataStreamSink = source.addSink(new ElasticsearchSink<>(config, transportAddresses, new ElasticsearchSinkFunction<Row>() {public IndexRequest createIndexRequest(Row element) {Map<String, Object> json = new HashMap<>();json.put("name22", element.getField(0).toString());json.put("no22", element.getField(1));json.put("age", 34);json.put("create_time", element.getField(2));return Requests.indexRequest().index("cc").type("mtype").id(element.getField(1).toString()).source(json);}@Overridepublic void process(Row element, RuntimeContext ctx, RequestIndexer indexer) {//利用requestIndexer进行发送请求,写入数据indexer.add(createIndexRequest(element));}}));env.execute("es demo");}private static java.sql.Timestamp getTimestamp(String str) throws Exception {
//		String string = "2016-10-24 21:59:06";SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");java.util.Date date=sdf.parse(str);java.sql.Timestamp s = new java.sql.Timestamp(date.getTime());return s;}

二、写入到Elasticsearch7

  • pom maven依赖
        <dependency><groupId>org.apache.flink</groupId><artifactId>flink-connector-elasticsearch7_2.11</artifactId><version>${flink.version}</version><scope>provided</scope></dependency>
  • 代码如下(示例):
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.elasticsearch.ElasticsearchSinkFunction;
import org.apache.flink.streaming.connectors.elasticsearch.RequestIndexer;
import org.apache.flink.streaming.connectors.elasticsearch7.ElasticsearchSink;
import org.apache.flink.types.Row;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Requests;import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EsSinkDemo {public static void main(String[] args) throws Exception {StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();Row row=Row.of("张三","001",getTimestamp("2016-10-24 21:59:06"));Row row2=Row.of("张三","002",getTimestamp("2016-10-24 21:50:06"));Row row3=Row.of("张三","002",getTimestamp("2016-10-24 21:51:06"));Row row4=Row.of("李四","003",getTimestamp("2016-10-24 21:50:56"));Row row5=Row.of("李四","004",getTimestamp("2016-10-24 00:48:36"));Row row6=Row.of("王五","005",getTimestamp("2016-10-24 00:48:36"));DataStreamSource<Row> source =env.fromElements(row,row2,row3,row4,row5,row6);Map<String, String> config = new HashMap<>();
//        config.put("cluster.name", "my-cluster-name");
// This instructs the sink to emit after every element, otherwise they would be buffered
//        config.put("bulk.flush.max.actions", "1");List<HttpHost> hosts = new ArrayList<>();hosts.add(new HttpHost("10.68.8.69",9200,"http"));ElasticsearchSink.Builder<Row> esSinkBuilder = new ElasticsearchSink.Builder<Row>(hosts,new ElasticsearchSinkFunction<Row>() {public IndexRequest createIndexRequest(Row element) {Map<String, Object> json = new HashMap<>();json.put("name22", element.getField(0).toString());json.put("no22", element.getField(1));json.put("age", 34);
//                json.put("create_time", element.getField(2));return Requests.indexRequest().index("cc").id(element.getField(1).toString()).source(json);}@Overridepublic void process(Row element, RuntimeContext ctx, RequestIndexer indexer) {//利用requestIndexer进行发送请求,写入数据indexer.add(createIndexRequest(element));}});esSinkBuilder.setBulkFlushMaxActions(100);//Sink操作source.addSink(esSinkBuilder.build());env.execute("es demo");}private static java.sql.Timestamp getTimestamp(String str) throws Exception {
//		String string = "2016-10-24 21:59:06";SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");java.util.Date date=sdf.parse(str);java.sql.Timestamp s = new java.sql.Timestamp(date.getTime());return s;}
}

总结

flink写入es5和es7 的区别是引入不同的flink-connector-elasticsearch,es7已没有type的概念故无需再设置type。

http://www.tj-hxxt.cn/news/112317.html

相关文章:

  • 宁波专业网站建设公司html简单网页成品
  • 网站开发与维护课程设计品牌推广工作内容
  • 企业网站哪家做的好在线培训app
  • 重庆营销网站建设色盲测试图第五版
  • 哈尔滨网站建设供应商优化关键词的作用
  • 郴州网站建设方案策划中国站长工具
  • 韩雪冬 网站新浪微博指数查询
  • 让wordpress主题适用插件seo网站优化案例
  • 有哪些网站做团购最好杭州推广公司
  • 网站建设设计梅州网络推广
  • 微信h5商城网站开发百度百科推广费用
  • 网站推广只能使用在线手段进行怎样建立一个网络销售平台
  • 哪些网站是用响应式布局做的小程序seo推广技巧
  • 做外链权重高的女性网站免费发布软文广告推广平台
  • 为什么用html5做网站电商网站seo优化
  • 杭州广众建设工程有限公司网站免费源码资源源码站
  • 怎么建网站做推广适合小学生的最新新闻
  • 免费地方网站网站alexa排名
  • 郑州网站建设一汉狮网络广告投放怎么做
  • 搭建网站的价格aso优化服务平台
  • 建设企业银行官网抖音视频排名优化
  • 北京手机网站制作公司郑州网站建设哪家好
  • 合肥网站建设哪个公司做得比较好百度seo最新算法
  • wordpress如何开发手机版企业网站的优化建议
  • wordpress设置html班级优化大师怎么下载
  • 网站本地环境搭建教程seo搜索引擎优化哪家好
  • wordpress制作购物网站天津快速关键词排名
  • 刚做淘客没有网站上海疫情最新消息
  • 企业网站快速排名媒体:北京不再公布疫情数据
  • 同程商旅企业版seo实战技巧100例