Elasticsearch的使用
Posted mxz1994
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Elasticsearch的使用相关的知识,希望对你有一定的参考价值。
今天更新了代码,发现竟然找不到货物列表了,查看历史,同事加了搜索优化
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的使用的主要内容,如果未能解决你的问题,请参考以下文章
使用标准库Ruby将数据标记到Elasticsearch批量中
Elasticsearch:如何在 Elasticsearch 中正确使用同义词功能