lucene和es总结
Posted Democracy and Science
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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/
以上是关于lucene和es总结的主要内容,如果未能解决你的问题,请参考以下文章