当前位置: 首页 > 工具软件 > namesearch > 使用案例 >

Elasticsearch常见错误及解决方法

凌俊名
2023-12-01

Elasticsearch常见错误及解决方法:

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

[2020-04-03T19:41:11,382][INFO ][o.e.n.Node               ] [txvm2019] starting ...
[2020-04-03T19:41:11,649][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [txvm2019] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[Cannot assign requested address];
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.2.0.jar:7.2.0]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.2.0.jar:7.2.0]
Caused by: org.elasticsearch.transport.BindTransportException: Failed to bind to [9300-9400]
	at org.elasticsearch.transport.TcpTransport.bindToPort(TcpTransport.java:389) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.transport.TcpTransport.bindServer(TcpTransport.java:355) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:136) ~[?:?]
	at org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport.doStart(SecurityNetty4Transport.java:81) ~[?:?]
	at org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransport.doStart(SecurityNetty4ServerTransport.java:43) ~[?:?]
	at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:59) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.transport.TransportService.doStart(TransportService.java:230) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:59) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.node.Node.start(Node.java:662) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:273) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:358) ~[elasticsearch-7.2.0.jar:7.2.0]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.0.jar:7.2.0]
	... 6 more
Caused by: java.net.BindException: Cannot assign requested address
	at sun.nio.ch.Net.bind0(Native Method) ~[?:?]
	at sun.nio.ch.Net.bind(Net.java:433) ~[?:?]
	at sun.nio.ch.Net.bind(Net.java:425) ~[?:?]
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:?]
	at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:132) ~[?:?]
	at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:563) ~[?:?]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1332) ~[?:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:503) ~[?:?]
	at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:488) ~[?:?]
	at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:984) ~[?:?]
	at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:259) ~[?:?]
	at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:366) ~[?:?]
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:405) ~[?:?]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) ~[?:?]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906) ~[?:?]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[?:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]

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

[2020-04-03T19:46:34,046][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [txvm2019] [controller/27023] [Main.cc@110] controller (64 bit): Version 7.2.0 (Build 65aefcbfce449b) Copyright (c) 2019 Elasticsearch BV
[2020-04-03T19:46:34,526][DEBUG][o.e.a.ActionModule       ] [txvm2019] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-04-03T19:46:34,867][INFO ][o.e.d.DiscoveryModule    ] [txvm2019] using discovery type [zen] and seed hosts providers [settings]
[2020-04-03T19:46:35,768][INFO ][o.e.n.Node               ] [txvm2019] initialized
[2020-04-03T19:46:35,768][INFO ][o.e.n.Node               ] [txvm2019] starting ...
[2020-04-03T19:46:35,923][INFO ][o.e.t.TransportService   ] [txvm2019] publish_address {172.17.0.1:9300}, bound_addresses {0.0.0.0:9300}
[2020-04-03T19:46:35,932][INFO ][o.e.b.BootstrapChecks    ] [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 ][o.e.n.Node               ] [txvm2019] stopping ...
[2020-04-03T19:46:36,012][INFO ][o.e.n.Node               ] [txvm2019] stopped
[2020-04-03T19:46:36,012][INFO ][o.e.n.Node               ] [txvm2019] closing ...
[2020-04-03T19:46:36,032][INFO ][o.e.n.Node               ] [txvm2019] closed

 

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

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][o.e.a.ActionModule       ] [txvm2019] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-04-03T19:51:41,799][INFO ][o.e.d.DiscoveryModule    ] [txvm2019] using discovery type [zen] and seed hosts providers [settings]
[2020-04-03T19:51:42,729][INFO ][o.e.n.Node               ] [txvm2019] initialized
[2020-04-03T19:51:42,729][INFO ][o.e.n.Node               ] [txvm2019] starting ...
[2020-04-03T19:51:42,890][INFO ][o.e.t.TransportService   ] [txvm2019] publish_address {172.17.0.1:9300}, bound_addresses {0.0.0.0:9300}
[2020-04-03T19:51:42,900][INFO ][o.e.b.BootstrapChecks    ] [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"
为了防止误删除,
可以设置 elasticsearch.yml属性 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. ...."
解决方法:
经过查找验证后发现出现该错误是因为5.x之后,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."
  }
}

 


 

 类似资料: