首页 > 解决方案 > Elasticsearch REST 搜索 API

问题描述

我对 elasticsearch nad REST API 的远程地址有问题(获取搜索结果)

我正在使用由 jHispter (logstash + Elasticsearch + Kibana) 创建的 ELK 堆栈。当我使用带有外部服务器地址的 REST 搜索 API(通过 cURL)时,我得到的结果比使用 localhost 时要少:

$ curl -X GET "http://localhost:9200/logstash-*/_search?q=Method:location"
{"took":993,"timed_out":false,"num_reduce_phases":13,"_shards": 
{"total":6370,"successful":6370,"skipped":0,"failed":0},"hits": 
{"total":8994099,"max_score":5.0447145,"hits":[..]}}

当从不同的服务器执行时,它返回较少数量的碎片和命中:

$ curl -X GET "http://SERVER_URL/logstash-*/_search?q=Method:location"
{"took":10,"timed_out":false,"_shards": 
{"total":120,"successful":120,"skipped":0,"failed":0},"hits": 
{"total":43,"max_score":7.5393815,"hits":[..]}}

如果我创建 ssh 隧道,它可以工作:

ssh -L 9201:SERVER_URL:9200 elk-stack

现在:

$ curl -X GET "localhost:9201/logstash-*/_search?q=Method:location"
{"took":640,"timed_out":false,"num_reduce_phases":13,"_shards": 
{"total":6370,"successful":6370,"skipped":0,"failed":0},"hits": 
{"total":8995082,"max_score":5.0447145,"hits":[..]}}

所以访问本地主机之外的数据肯定有一些问题,但我无法在配置中找到如何更改它(可能是某种默认行为以防止从远程访问时数据泄漏?)

标签: elasticsearchkibana

解决方案


你应该配置你的主机

为此,在 config/elasticsearch.yml 文件中放入这一行:

network.host: 0.0.0.0

推荐阅读