ElasticSearch 几个比较实用的配置项
1、IK分词器插件安装
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
选择与自己ElasticSearch版本号一致的zip包进行下载
下载完后复制到ElasticSearch安装路径的plugins目录下,然后解压缩,因为解压后文件夹名字有点长,可以修改一下,一般大家都习惯性地修改为ik
然后就是分词字典配置
进入ik分词器路径下的config目录,修改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">a.dic;b.dic</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
配置完后重启ES
2、查询超过10000条数据的分页
先看看报错
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Result window is too large, from + size must be less than or equal to: [10000] but was [10010]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "public_resource_master",
"node" : "C38y1RXeTQKvLw8U0cgqWw",
"reason" : {
"type" : "illegal_argument_exception",
"reason" : "Result window is too large, from + size must be less than or equal to: [10000] but was [10010]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."
}
}
],
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Result window is too large, from + size must be less than or equal to: [10000] but was [10010]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Result window is too large, from + size must be less than or equal to: [10000] but was [10010]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."
}
}
},
"status" : 400
}
仔细阅读错误消息(This limit can be set by changing the [index.max_result_window] index level setting.)后,发现可以通过更改 [index.max_result_window] 索引级别设置来设置此限制。
PUT your_index_name/_settings
{
"index": {
"max_result_window": 1000000000 # 默认为10000,修改后立即生效,无须重启ES
}
}
3、跨域设置
# 修改elasticsearch.yml文件,添加一下配置
http.cors.enabled: true
http.cors.allow-origin: "*"
#
http.cors.allow-headers: Content-Type,Accept,Authorization, x-requested-with
4、开启远程访问
# 修改elasticsearch.yml配置文件,修改设置
network.host: 0.0.0.0
# 转发
transport.host: localhost
# TCP端口转发
transport.tcp.port: 9300
# http端口
http.port: 9200
注:开启远程访问后,防火墙也要开放9200端口入站规则,如果是阿里云服务器还要添加安全组规则