ES搜索引擎的使用

  1. 用seatunnel同步Oracle官网的数据存储到es里

  1. 搜索展示


  1. 配置seatunnel配置文件

cd /seatunnel/apache-seatunnel-incubating-2.3.0/config

#修改example01.conf文件
vim example01.conf

内容大致为

env {
    execution.parallelism = 3
    job.mode = "BATCH"
    job.name = "es_DataSynchronization_apiProd"
}
# 在source所属的块中配置数据源
source {
Jdbc {
       driver ="oracle.jdbc.driver.OracleDriver"
       url ="jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1530/APEXPDB1"
        user ="xxx"
        password ="xxx"
        query ="select * from datatech.v_api_prod_desc_85"
    }
}
# 在transform的块中声明转换插件
transform {

}
# 在sink块中声明要输出到哪
sink {
    Elasticsearch {
        hosts = ["127.0.0.1:9200"]
        index = "index"
    }
}

保存退出,进入es可视化界面或者postman,linux也可以

创建索引

注意:创建映射时,要先比对数据库字段,比如说数据库有A,B,C,D四个字段,那么创建索引要创建四次

content改为A,B,C,D分别运行一次即可

下面是linux索引,postman请求的那种就不写了,看着改一下就行

#创建索引
curl -XPUT http://localhost:9200/index

#创建映射
curl -XPOST http://localhost:9200/index/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart"
            }
        }

}'

#查看索引
curl -XGET http://localhost:9200/index/_mapping

索引创建完后同步数据

cd /seatunnel/apache-seatunnel-incubating-2.3.0

#执行同步任务
./bin/start-seatunnel-flink-connector-v2.sh --config ./config/example01.conf

去es可视化界面刷新一下,可以看到数据同步成功

点击基本查询,把你数据库字段全放上去

➀should 它的意思是或,等于SQL语句的or

如果是must 它的意思是且,等于SQL语句的and

➁你要查询的字段,默认是模糊搜索

➂点击“+”增加条件

➃设置查询结果的返回数量

➄点击勾选,可以有7和8

➅搜索

➆勾选5才会显示,点击出现8

➇查询所用的sql语句

新建一个.txt页面


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Lightly-HTML-Project</title>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>

<script type="text/javascript">

var container = document.getElementById("container");
    //点击搜索按钮
     function ClickSearch(){
     //点击搜索清空div
     $('#div').empty();
        //获取输入框内容
           var InputBoxContent = document.getElementById("searchTxt").value;    
           var query = "8获取到的sql,粘贴到这,"
           //var query = {"query":{"bool":{"must":[],"must_not":[],"should":[{"match":{"COL4":"***"}},{"match":{"COL3":"***"}},{"match":{"COL2":"***"}},{"match":{"COL16":"***"}},{"match":{"COL17":"***"}},{"match":{"COL12":"***"}},{"match":{"COL11":"***"}},{"match":{"COL13":"***"}},{"match":{"COL10":"***"}},{"match":{"PRODID":"***"}}]}},"from":0,"size":250,"sort":[],"aggs":{}};
        //判断搜索条件
        if(InputBoxContent.trim().length == 0){
        //输入框为空时  全查
        var query ={"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],"should":[]}},"from":0,"size":250,"sort":[],"aggs":{}}
        }else{
        //输入框不为空时   执行***替换为输入框内容
        query.query.bool.should.forEach(function(item) { for (var key in item.match) { if (item.match[key] === '***') { item.match[key] = InputBoxContent.trim()}}});
        }
        
        //执行ajax请求
                $.ajax({
                    type: "POST",
                    dataType:"json",
                    contentType:"application/json;charset=utf-8",
                    data:JSON.stringify(query),
                    url: 'http://127.0.0.1:9200/index/_search/'})
                    .done(function(data) { 
                    // 生成表格标题行
                    //根据自己的改
                        $('#div').append('<table style="width:100%!!(MISSING);height:100%!!(MISSING);margin:0;"><tr><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col4     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col3     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col2     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col16     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col17     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col12    </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col11     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col13     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">Col10     </th><th style="padding: 5px;margin: 5px;border: 1px solid #000;">PRODID     </th></tr></table>');
                    $.each(data.hits.hits, function(index, item) {
                    console.log(index + '   ' + item);
                    console.log(JSON.stringify(item._source.COL4));
                     // 将内容添加到表格中
                     $('#div').append('<tr><td>' +item._source.COL4 + '</td><td>' + item._source.COL3 + '</td><td>' + item._source.COL2 + '</td><td>' + item._source.COL16 + '</td><td>' + item._source.COL17 + '</td><td>' + item._source.COL12 + '</td><td>' + item._source.COL11 + '</td><td>' + item._source.COL13 + '</td><td>' + item._source.COL10 + '</td><td>' + item._source.PRODID + '</td></tr>'); }); 
                     
                    $('#div').append('</table>');
                    });
               
            
   }

  </script>
</head>
<body>
    <div class="box">
    <input id="searchTxt" type="text" class="input" placeholder="请输入关键字" />
    <button type="button" onclick="ClickSearch()">搜索一下</button>
</div>
<div id="div">
        假如我是官网
    </div>
</html>

保存,后缀改为html,打开测试。


设置定时任务

#查看当前用户的定时任务
crontab -l

#查看指定用户
crontab -l  -u xxx

#修改定时任务
crontab -r

定时的例子,参考别人文档

* * * * *  /usr/local/test.sh   # 每分钟执行一次test.sh
0 * * * * echo '我是一句话' >> /root/date.txt   # 每小时0分的时候向date.txt文件中加入一句话
* 1 * * 0 rm -rf /root/date1   #每个星期的星期天的1点左右删除date1文件

定时表达的意思

*    *    *    *    *
-    -    -    -    -
|    |    |    |    |
|    |    |    |    +----- 星期中星期几 (0 - 6) (星期天 为0)
|    |    |    +---------- 月份 (1 - 12) 
|    |    +--------------- 一个月中的第几天 (1 - 31)
|    +-------------------- 小时 (0 - 23)
+------------------------- 分钟 (0 - 59)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值