0
对于Elasticsearch和Ruby脚本来说,我是新来的,请帮我解决这个问题。我想通过cron作业每天从索引中添加/删除别名。从Ruby脚本中调用Elasticsearch Rest API
我试着用如下的shell脚本和它的工作如预期
curl -XPOST "http://$es_host:9200/_aliases" -d "$json"
的Ruby脚本
#! /usr/bin/env ruby
require 'rubygems'
require 'json'
require 'rest_client'
target="http://localhost:9200/_aliases"
request = RestClient::Request.new(
:method => :post,
:url => target,
:payload => input)
puts request.execute
输入有效的JSON(我测试)。但Ruby脚本抛出错误。
> [email protected]/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 400 Bad Request (RestClient::BadRequest) from
> /.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result' from
> /.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit' from
> /.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/net/http.rb:745:in
> `start' from
> /.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit' from
> /.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in
> `execute' from es_alias.rb:56:in `<main>'
P.S - Ruby脚本打印所有别名,如果我只是删除有效载荷并尝试。
输入定义在哪里? – 2014-12-13 00:10:28
其有效的json,由于安全原因未包括它。 – 2014-12-13 00:13:31
尝试[在RestClient中开启日志记录](https://github.com/rest-client/rest-client#logging)并在此处发布结果。 – 2014-12-13 00:21:33