# Ruby request and logstash

**URL:** https://discuss.elastic.co/t/ruby-request-and-logstash/196570
**Category:** Logstash
**Created:** [August 23, 2019, 5:29pm UTC](https://discuss.elastic.co/t/ruby-request-and-logstash/196570 "2019-08-23T17:29:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![He\_Pamela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/he_pamela/32/42370_2.png) [@He\_Pamela](https://discuss.elastic.co/u/He_Pamela)
#### Post date: [August 23, 2019, 5:29pm UTC](https://discuss.elastic.co/t/ruby-request-and-logstash/196570/1 "2019-08-23T17:29:06Z")

</div>

Hi,

I'm trying to make a ruby request to Elasticsearch using Logstash and ruby.  
this is my filter part in the config file.

```
filter {
       
json {
              source => "message"
           }
         }

     ruby {
                   init => "
                                require 'net/http'
                                require 'net/https'
                                require 'uri'
                                require 'json'
                        "
                   code => "
                             puts uri = URI('https://xxx.xxx.xx.xxx:9200/index/doc/_search')
        
                                Net::HTTP.start(uri.host, uri.port,
                                  :use_ssl => uri.scheme == 'https', 
                                  :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                                  request = Net::HTTP::Get.new uri.request_uri
                                  request.Content-Type = 'application/json'
                                  request.basic_auth 'user', 'password'
                                  request.body = '{\n \"query\": {\n \"term\": {\n \"Carriles.keyword\": \"DAI-CAI LOPEZMESA-P1-L0\"\n }\n }\n}'
                                  response = http.request request # Net::HTTPResponse object
                                  puts response.body
                                                                 
                               end
        
                     

                             "
                 

                }
                mutate { remove_field => ["message"] }
}

```

I need the response from the query to elastic. But I only get this message from ruby and I don't now what is wrong.

> [ERROR] 2019-08-23 12:27:45.985 [Ruby-0-Thread-4: :1] ruby - Ruby exception occurred: end of file reached

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [August 23, 2019, 6:17pm UTC](https://discuss.elastic.co/t/ruby-request-and-logstash/196570/2 "2019-08-23T18:17:58Z")

</div>

Not sure what the exception means, but you do know there is an [elasticsearch filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-elasticsearch.html) you can use, right?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 20, 2019, 6:18pm UTC](https://discuss.elastic.co/t/ruby-request-and-logstash/196570/3 "2019-09-20T18:18:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
