ElasticSearch 几个比较实用的配置

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端口入站规则,如果是阿里云服务器还要添加安全组规则

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wu575437

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值