本地Elasticsearch环境出现404错误(index_not_found_exception)求助
解决Elasticsearch的index_not_found_exception(404错误)
这个错误逻辑很直白:你要操作的invoices索引压根没创建,Elasticsearch找不到它。下面是一步步的解决思路:
1. 先确认索引是否真的不存在
先通过命令行或者Kibana Dev Tools列出当前所有索引,核实invoices确实不在列表里:
# curl命令方式 curl -X GET "http://localhost:9200/_cat/indices?v" # Kibana Dev Tools执行方式 GET /_cat/indices?v
如果输出里完全看不到invoices,那就是真的没创建,继续往下走。
2. 手动创建invoices索引
最简单的创建方式是直接发送PUT请求:
# curl方式 curl -X PUT "http://localhost:9200/invoices" # Kibana Dev Tools方式 PUT /invoices
执行成功后会返回类似{"acknowledged":true,"shards_acknowledged":true,"index":"invoices"}的响应,说明索引创建完成。
如果你的业务需要自定义索引规则(比如指定字段类型、分词器),可以带mapping参数创建:
PUT /invoices { "mappings": { "properties": { "invoice_number": {"type": "keyword"}, "amount": {"type": "float"}, "created_at": {"type": "date"} } } }
3. 排查其他潜在问题
- 索引名拼写错误:Elasticsearch索引名是大小写敏感的,检查你代码里写的是不是
Invoices或者其他拼写失误,确保和实际创建的索引名完全一致。 - 自动创建索引被禁用:如果你的应用期望自动创建索引,但Elasticsearch的
action.auto_create_index配置被设为false,就会导致写入时无法自动生成索引。可以先检查这个配置:
如果需要开启自动创建,可设置为GET /_cluster/settings?include_defaults=true&filter_path=**.action.auto_create_indextrue(允许所有索引自动创建),或者指定允许的索引模式比如+invoices,-*(仅允许invoices自动创建):PUT /_cluster/settings { "persistent": { "action.auto_create_index": "+invoices,-*" } }
完成以上操作后,再尝试操作invoices索引,应该就不会再触发404错误了。
内容的提问来源于stack exchange,提问作者Anand
相关产品推荐
相关产品推荐

