Elasticsearch常见错误及解决方式

时间:2024-10-19 09:59:25

Elasticsearch常见错误及解决方法:

1、启动时候报错:Caused by: : Cannot assign requested address
解决方法:打开配置文件 将 : 192.168.0.1 修改为本机IP 0.0.0.0

[2020-04-03T19:41:11,382][INFO ][               ] [txvm2019] starting ...
[2020-04-03T19:41:11,649][WARN ][] [txvm2019] uncaught exception in thread [main]
: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[Cannot assign requested address];
    at (:163) ~[elasticsearch-7.2.:7.2.0]
    at (:150) ~[elasticsearch-7.2.:7.2.0]
    at (:86) ~[elasticsearch-7.2.:7.2.0]
    at (:124) ~[elasticsearch-cli-7.2.:7.2.0]
    at (:90) ~[elasticsearch-cli-7.2.:7.2.0]
    at (:115) ~[elasticsearch-7.2.:7.2.0]
    at (:92) ~[elasticsearch-7.2.:7.2.0]
Caused by: : Failed to bind to [9300-9400]
    at (:389) ~[elasticsearch-7.2.:7.2.0]
    at (:355) ~[elasticsearch-7.2.:7.2.0]
    at .netty4.(:136) ~[?:?]
    at .netty4.(:81) ~[?:?]
    at .netty4.(:43) ~[?:?]
    at (:59) ~[elasticsearch-7.2.:7.2.0]
    at (:230) ~[elasticsearch-7.2.:7.2.0]
    at (:59) ~[elasticsearch-7.2.:7.2.0]
    at (:662) ~[elasticsearch-7.2.:7.2.0]
    at (:273) ~[elasticsearch-7.2.:7.2.0]
    at (:358) ~[elasticsearch-7.2.:7.2.0]
    at (:159) ~[elasticsearch-7.2.:7.2.0]
    ... 6 more
Caused by: : Cannot assign requested address
    at .bind0(Native Method) ~[?:?]
    at (:433) ~[?:?]
    at (:425) ~[?:?]
    at (:223) ~[?:?]
    at (:132) ~[?:?]
    at $(:563) ~[?:?]
    at $(:1332) ~[?:?]
    at (:503) ~[?:?]
    at (:488) ~[?:?]
    at (:984) ~[?:?]
    at (:259) ~[?:?]
    at $(:366) ~[?:?]
    at (:163) ~[?:?]
    at (:405) ~[?:?]
    at (:500) ~[?:?]
    at $(:906) ~[?:?]
    at $(:74) ~[?:?]
    at (:745) [?:1.8.0_121]


2、错误:max number of threads [2048] for user [elasticsearch] is too low, increase to at least [4096]
解决方法:编辑 /etc/security/,追加以下内容;
 soft nofile 65536
 hard nofile 65536

[2020-04-03T19:46:34,046][INFO ][] [txvm2019] [controller/27023] [@110] controller (64 bit): Version 7.2.0 (Build 65aefcbfce449b) Copyright (c) 2019 Elasticsearch BV
[2020-04-03T19:46:34,526][DEBUG][       ] [txvm2019] Using REST wrapper from plugin 
[2020-04-03T19:46:34,867][INFO ][    ] [txvm2019] using discovery type [zen] and seed hosts providers [settings]
[2020-04-03T19:46:35,768][INFO ][               ] [txvm2019] initialized
[2020-04-03T19:46:35,768][INFO ][               ] [txvm2019] starting ...
[2020-04-03T19:46:35,923][INFO ][   ] [txvm2019] publish_address {172.17.0.1:9300}, bound_addresses {0.0.0.0:9300}
[2020-04-03T19:46:35,932][INFO ][    ] [txvm2019] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max number of threads [2048] for user [elasticsearch] is too low, increase to at least [4096]
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2020-04-03T19:46:35,978][INFO ][               ] [txvm2019] stopping ...
[2020-04-03T19:46:36,012][INFO ][               ] [txvm2019] stopped
[2020-04-03T19:46:36,012][INFO ][               ] [txvm2019] closing ...
[2020-04-03T19:46:36,032][INFO ][               ] [txvm2019] closed


 

3、错误:cluster.initial_master_nodes] must be configured
解决方法:
在elasticsearch的config目录下,修改配置文件,将下面的配置加入到该配置文件中:

ip替换host1等,多节点请添加多个ip地址,单节点可写按默认来
#配置以下三者,最少其一
#[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes]
cluster.initial_master_nodes: ["node-1"] #这里的node-1为node-name配置的值

[2020-04-03T19:51:41,427][DEBUG][       ] [txvm2019] Using REST wrapper from plugin 
[2020-04-03T19:51:41,799][INFO ][    ] [txvm2019] using discovery type [zen] and seed hosts providers [settings]
[2020-04-03T19:51:42,729][INFO ][               ] [txvm2019] initialized
[2020-04-03T19:51:42,729][INFO ][               ] [txvm2019] starting ...
[2020-04-03T19:51:42,890][INFO ][   ] [txvm2019] publish_address {172.17.0.1:9300}, bound_addresses {0.0.0.0:9300}
[2020-04-03T19:51:42,900][INFO ][    ] [txvm2019] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured


 

4、删除数据时错误:"reason":"Wildcard expressions or all indices are not allowed"
解决方法:
删除所有索引时
curl -X DELETE "http://localhost:9200/*"
或者
curl -X DELETE "localhost:9200/_all"
为了防止误删除,
可以设置 属性 action.destructive_requires_name为true,
禁止使用通配符或_all删除索引,
必须使用名称或别名才能删除该索引。
修改为false即可删除所有
action.destructive_requires_name: false

{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"}],"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"},"status":400}


5、创建索引错误:The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.
解决方法:
修改为:

{
    "settings": {
        "number_of_shards": 3,
        "number_of_replicas": 2
    },
    "mappings": {
            "properties": {
                "commodity_id": {
                    "type": "long"
                },
                "commodity_name": {
                    "type": "text"
                },
                "picture_url": {
                    "type": "text"
                },
                "price": {
                    "type": "double"
                }
            }
    }
}


出现这个的原因是,elasticsearch7默认不在支持指定索引类型,默认索引类型是_doc,如果想改变,则配置include_type_name: true 即可(这个没有测试,官方文档说的,无论是否可行,建议不要这么做,因为elasticsearch8后就不在提供该字段)。

{
   "error":    {
      "root_cause": [      {
         "type": "illegal_argument_exception",
         "reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
      }],
      "type": "illegal_argument_exception",
      "reason": "The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true."
   },
   "status": 400
}

6、聚合查询时错误:"Fielddata is disabled on text fields by default. ...."
解决方法:
经过查找验证后发现出现该错误是因为之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,这样做的目的是为了节省内存空间。所以如果需要进行聚合操作,需要单独开启。执行以下代码(city为相关text的字段名称)

PUT myindex/_mapping
{
  "properties": {
    "city": { 
      "type":     "text",
      "fielddata": true
    }
  }
}


 

"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
  "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [city] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
  }
}