Domino毫秒级查询利器Elasticsearch(一)

52 篇文章 1 订阅
39 篇文章 29 订阅

      一般的关系数据库,到了亿级别的时候,查询都会感觉慢。 目前流行什么查询呢?我们的不少java项目都使用了Elasticsearch来解决查询问题。目前哪些平台在使用Elasticsearch? Stack Overflow、GitHub、电商平台等。
      关系数据同步到Elasticsearch网上已经有不少了。现在给大家介绍如何从Domino同步到Elasticsearch。
      如果在Domino的数据库查询,上100W大量数据之后,更是慢得让用户不能接受。从Domino 10开始又多了一种数据库查询方法,Domino Query Language(简称DQL),刚开始只支持nodejs开放,后期会支持ls、java一起。看了一些资料DQL查询比以前的方式要快不少。由于没有使用nodejs开发,一直没有测试。

           Elasticsearch有非常多的优点,查询又是毫秒级别的,能否集成到Domino里面来?在以前博客已经有介绍过Domino集成关系数据库,目前关系数据库如果在上亿级的记录及查询,已经有不少资料推荐使用Elasticsearch。特别是一些开源的java平台,提及最多查询数据库方式使用Elasticsearch。让查询上亿级的数据到毫秒级。

         我们的Domino是否可以同步?Elasticsearch去网上下载,不介绍安装Elasticsearch。以下简要介绍Domino同步到Elasticsearch的过程截图:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;

import com.alibaba.fastjson.JSONObject;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

      try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();


          Date d1 = new Date();     
        Database db = session.getCurrentDatabase();
        View view =db.getView("AllNames");
        ViewEntryCollection vc=view.getAllEntries();
        ViewEntry tmpentry=null;
		ViewEntry entry=vc.getFirstEntry();
		
		System.out.println(vc.getCount());
		
	
		int i=0;
	    while (entry != null) {
	    	i++;	 	    	
	    	String temp="{\"Name\":\""+entry.getColumnValues().elementAt(0).toString()
	    			+"\",\"EMail\":\""+entry.getColumnValues().elementAt(1).toString()+"\"}";
	    	temp=HttpSendSoapPost("PUT","http://localhost:9200/xpages/ext/"+entry.getUniversalID(),temp);
	    	System.out.println(i);
	    	
	        tmpentry = vc.getNextEntry();
	        entry.recycle();
	        entry = tmpentry;
	      }
		
	    Date d2 = new Date();
		System.out.println(d2.getTime() - d1.getTime());
		System.out.println("****** END ********");	
		
      } catch(Exception e) {
          e.printStackTrace();
       }
   }
    
    public static String HttpSendSoapPost(String Method,String strurl,String xml){
		HttpURLConnection connection = null;
		InputStream is = null;
		BufferedReader br = null;
		String result = null;// 返回结果字符串
		OutputStream out = null;
		
		//Date d1 = new Date();

		try {
		
			// 创建远程url连接对象
			URL url = new URL(strurl);
			// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
			
			connection = (HttpURLConnection) url.openConnection();
			// 设置连接方式:GET,POST
			if(Method.equals("")){
				connection.setRequestMethod("POST");
			}else{
				connection.setRequestMethod(Method);
			}
			

			connection.setDoInput(true);
			connection.setDoOutput(true);
			
			connection.setRequestProperty("Content-Type", "application/json");
			//这里必须要写,否则出错
			//connection.setRequestProperty("SOAPAction", "");			
						
			// 设置连接主机服务器的超时时间:15000毫秒
			connection.setConnectTimeout(15000);
			// 设置读取远程返回的数据时间:60000毫秒
			connection.setReadTimeout(60000);

			// 发送请求
			connection.connect();
			out = connection.getOutputStream(); // 获取输出流对象
			connection.getOutputStream().write(xml.getBytes("UTF-8")); // 将要提交服务器的SOAP请求字符流写入输出流
			
			out.flush();
			out.close();

			//System.out.println(connection.getResponseCode());

			// 通过connection连接,获取输入流
			if (connection.getResponseCode() == 200 || connection.getResponseCode() == 201) {
				is = connection.getInputStream();
				// 封装输入流is,并指定字符
				br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
				// 存放数据
				StringBuffer sbf = new StringBuffer();
				String temp = null;
				while ((temp = br.readLine()) != null) {
					sbf.append(temp);
					sbf.append("\r\n");
				}
				result = sbf.toString();
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 关闭资源
			if (null != br) {
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			if (null != is) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			connection.disconnect();// 关闭远程连接

		}
			
		//System.out.println();
		return result;
	}
    
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weijia3624

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值