Elasticsearch
安装:
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.4.2
修改文件夹访问权限:
chmod -R 777 /mydata/elasticsearch/
安装:
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.56.10:9200 -p 5601:5601 -d kibana:7.4.2
设置开机自启动:
docker update ece --restart=always
docker update cd8 --restart=always
配置远程扩展字典:
[root@loaclhost mydata]# ls elasticsearch mysql nginx redis [root@loaclhost mydata]# cd elasticsearch/ [root@loaclhost elasticsearch]# ls config data plugins [root@loaclhost elasticsearch]# cd plugins/ [root@loaclhost plugins]# ls ik [root@loaclhost plugins]# cd ik [root@loaclhost ik]# ls commons-codec-1.9.jar commons-logging-1.2.jar config elasticsearch-analysis-ik-7.4.2.jar httpclient-4.5.2.jar httpcore-4.4.4.jar plugin-descriptor.properties plugin-security.policy [root@loaclhost ik]# cd config/ [root@loaclhost config]# ls extra_main.dic extra_single_word_full.dic extra_stopword.dic main.dic quantifier.dic suffix.dic extra_single_word.dic extra_single_word_low_freq.dic IKAnalyzer.cfg.xml preposition.dic stopword.dic surname.dic [root@loaclhost config]# cat IKAnalyzer.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 扩展配置</comment> <!--用户可以在这里配置自己的扩展字典 --> <entry key="ext_dict"></entry> <!--用户可以在这里配置自己的扩展停止词字典--> <entry key="ext_stopwords"></entry> <!--用户可以在这里配置远程扩展字典 --> <entry key="remote_ext_dict">http://192.168.56.10/es/fenci.txt</entry> <!--用户可以在这里配置远程扩展停止词字典--> <!-- <entry key="remote_ext_stopwords">words_location</entry> --> </properties> [root@loaclhost config]#
es目录:
t/mydata/nginx/html/es
添加客户端:<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.2</version>
</dependency>
配置文件:
@Configuration
public class GulimallElasticSearchConfig {
// 单例的
public static final RequestOptions COMMON_OPTIONS;
static {
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
// builder.addHeader("Authorization", "Bearer " + TOKEN);
// builder.setHttpAsyncResponseConsumerFactory(
// new HttpAsyncResponseConsumerFactory
// .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
COMMON_OPTIONS = builder.build();
}
@Bean
public RestHighLevelClient restHighLevelClient() {
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("192.168.56.10", 9200, "http")));
return client;
}
}
构建检索请求:
1.构建bool - query
2.排序,分页,高亮
3.聚合(类似于sql中的group by)
客户端执行检索