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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM