码迷,mamicode.com
首页 > 其他好文 > 详细

Elasticsearch的使用

时间:2018-10-06 20:31:23      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:boolean   connect   int   autowire   tcl   valueof   new   customize   arch   

今天更新了代码,发现竟然找不到货物列表了,查看历史,同事加了搜索优化

Elasticsearch 应该和以前学的luncence(也忘了)分词查询差不多吧

具体配置 也就是 导包   引入客户端, 启动Elsticsearch服务器  具体代码官网有

@Configuration
public class ElasticsearchConfig {
	
	@Resource
	private ConfigHelper configHelper;
	
//	private String host = "elasticsearch.dev.qinsilk.com";
//	private int port = 80;
	private String schema = "http";
	private int connectTimeOut = 1000;
	private int socketTimeOut = 30000;
	private int connectionRequestTimeOut = 500;
	private int maxConnectNum = 100;
	private int maxConnectPerRoute = 100;
	private HttpHost httpHost;
	private boolean uniqueConnectTimeConfig = true;
	private boolean uniqueConnectNumConfig = true;
	private RestClientBuilder builder;
	private RestHighLevelClient client;

	@Bean(autowire = Autowire.BY_NAME, name = "restHighLevelClient")
	public RestHighLevelClient client() {
		httpHost = new HttpHost(
				configHelper.getValue(EsConstants.ES_HOST), 
				Integer.valueOf(configHelper.getValue(EsConstants.ES_PORT)),
				schema);
		builder = RestClient.builder(httpHost);
		if (uniqueConnectTimeConfig) {
			setConnectTimeOutConfig();
		}
		if (uniqueConnectNumConfig) {
			setMutiConnectConfig();
		}
		client = new RestHighLevelClient(builder);
		return client;
	}

	/** * 异步httpclient的连接延时配置 */
	public void setConnectTimeOutConfig() {
		builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
			@Override
			public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
				requestConfigBuilder.setConnectTimeout(connectTimeOut);
				requestConfigBuilder.setSocketTimeout(socketTimeOut);
				requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
				return requestConfigBuilder;
			}
		});
	}

	/** * 异步httpclient的连接数配置 */
	public void setMutiConnectConfig() {
		builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
			@Override
			public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
				httpClientBuilder.setMaxConnTotal(maxConnectNum);
				httpClientBuilder.setMaxConnPerRoute(maxConnectPerRoute);
				return httpClientBuilder;
			}
		});
	}

  下载 E和Kibana(可视化工具) 启动bat

利用RestletClient 访问

新建和删除 Index

PUT ‘localhost:9200/weather‘

  

 

Elasticsearch的使用

标签:boolean   connect   int   autowire   tcl   valueof   new   customize   arch   

原文地址:https://www.cnblogs.com/mxz1994/p/9748264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!