使用R连接到AWS Elasticsearch Service - 获取404错误

时间:2016-11-30 17:52:50

标签: r amazon-web-services elasticsearch

我正在尝试通过名为elastic的R中的包查询AWS ElasticSearch Service(AWS ES)。我在尝试连接服务器时遇到错误。

以下是一个例子:

install.packages("elastic")
library(elastic)
aws_endpoint = "<secret>"
   # I am certain the endpoint exists and is correct, as it functions with Kibana
aws_port = 80    
   # I have tried 9200, 9300, and 443 with no success

connect(es_host = aws_endpoint, 
    es_port = 80,
    errors = "complete")
ping()
Search(index = "foobar", size = 1)$hits$hits

无论是ping服务器还是实际尝试搜索文档,都会检索此错误:

Error: 404 - no such index
ES stack trace:
  type: index_not_found_exception
  reason: no such index
  resource.type: index_or_alias
  resource.id: us-east-1.es.amazonaws.com
  index: us-east-1.es.amazonaws.com

我已进入AWS ES仪表板并确定我正在使用存在的索引。为什么这个错误?

我想我对传输协议有些误解。 elastic与elasticsearch的HTTP API进行交互。我觉得这很好。

如何在R和AWS ES之间建立适当的连接?

R version 3.3.0 (2016-05-03); elastic_0.7.8

1 个答案:

答案 0 :(得分:2)

解决了它。

必须将

es_path指定为空字符串(""。否则,connect()将AWS区域(即us-east-1.es.amazonaws.com)理解为路径。我想connect()在HTTP请求中添加了误解的路径following the format shown here

connect(es_host = aws_endpoint, 
   es_port = 80,
   errors = "complete",
   es_path = "" 
)

为了清楚起见,我实际使用的参数如下所示,但它们不应该有所作为。 修复es_path是关键

connect(es_host = aws_endpoint, 
    es_port = 443, 
    es_path = "", 
    es_transport_schema  = "https")