2014-12-12 86 views
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腳本打印所有別名,如果我只是刪除有效載荷並嘗試。

+0

輸入定義在哪裏? – 2014-12-13 00:10:28

+0

其有效的json,由於安全原因未包括它。 – 2014-12-13 00:13:31

+0

嘗試[在RestClient中開啓日誌記錄](https://github.com/rest-client/rest-client#logging)並在此處發佈結果。 – 2014-12-13 00:21:33

回答