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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章