lucene和es总结

一、首先介绍lucene涉及到的排序过程

1.1、如何自定义排序对象

你可以自定义collector对象;

亦可以自定义comparator对象;

可以自定义scoredoc对象,决定如何处理结果集合;

1.2、这几种自定义之间有何区别?

自定义collector和comparator有什么区别呢????????

Besides building your own Collector to customize how the results are stored and sorted, another way to customize results sorting is to implement your own FieldComparator for SortField. Note that this customization only deals with the sorting aspect of the result set; it does not give you the flexibility to filter out results, as you would have with Collector.

 

 

二、ES master slave介绍

master es中的作用就是:it’s the responsability of the master node to allocate the shards equally among the nodes. 

requests分为两种:index requests和 search requests;两种请求可以落到集群任何一台机器。

》》然后对于TransportClient本身就是做的round robin形式,

The TransportClient connects remotely to an elasticsearch cluster using the transport module. It does not join the cluster, but simply gets one or more initial transport addresses and communicates with them in round robin fashion on each action

所以你只需要new的时候给定 addresses就好了

    
 private TransportClient client=null;
Settings settings = Settings.settingsBuilder().put("cluster.name", cluster_name).build();
            client = TransportClient.builder().settings(settings).build() ;
            for(String host_port:host_ports.split(",")){
               String[] hostAndPort=host_port.split(":");
               if(hostAndPort.length==2){
                   String host=hostAndPort[0].trim();
                   int port=Integer.valueOf(hostAndPort[1].trim());
                   client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
               }
            }   

而其中的配置文件可以是

cluster.name: cluster_name

host.ports: ip1:9300,ip2:9300,ip3:9300

>>对于client的关闭主要是三部曲

client.close();
client.threadPool().shutdown();
client = null;

这个坑的解释是https://discuss.elastic.co/t/correct-way-to-use-transportclient-connection-object/17947/8

 

三、参考文献

http://blog.trifork.com/2013/10/24/how-to-avoid-the-split-brain-problem-in-elasticsearch/

https://github.com/xuxueli/xxl-search/blob/master/xxl-search-client/src/main/java/com/xxl/search/client/es/ElasticsearchUtil.java

 

转载于:https://www.cnblogs.com/amazement/p/6218917.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值