# Help with Ruby code please (Using user input in searches)

**URL:** <https://discuss.elastic.co/t/help-with-ruby-code-please-using-user-input-in-searches/200545>\
**Category:** Elasticsearch\
**Created:** [September 21, 2019, 7:44pm UTC](https://discuss.elastic.co/t/help-with-ruby-code-please-using-user-input-in-searches/200545 "2019-09-21T19:44:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelberg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michaelberg/32/51063_2.png) [@michaelberg](https://discuss.elastic.co/u/michaelberg)\
**Post date:** [September 21, 2019, 7:44pm UTC](https://discuss.elastic.co/t/help-with-ruby-code-please-using-user-input-in-searches/200545/1 "2019-09-21T19:44:48Z")

</div>

```
puts " ****************************************************"
puts "* This program will search Elastic Search Cloud *"
puts "* based on a single field name and a single value *"
puts "* for the given field name *"
puts " ****************************************************"
puts
puts "Which field name in Elasticsearch would you like to search on?"
field_name = gets.chomp
#
puts "What value for [" + field_name + "] would you like to search for?"
field_value = gets.chomp
#
puts
puts "Searching for '" + field_value + "' in [" + field_name + "]"
puts
#######################################
# MAIN CODE BODY
#######################################
response = es.search index: 'filebeat-*',
                     scroll: '1m',
                     body: { 
                         query: {
                              bool: {
                                  must: [
                                      {match: { "event.id": "CLAPr91aCeIQsNNS04"}}
                                  ]
                              }
                         } 
                     }

```

Good Morning Everyone ... this code works just fine if I hard code the field and value in the match statement. For the life of me I cannot sort out how to get **field\_name** and **field\_value** (obtained from user input at the beginning of the code) inserted into the match statement ...

It's likely something super simple and I am just missing it ...

Appreciate any feedback ... thanks so much!

---

<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:** [October 19, 2019, 7:44pm UTC](https://discuss.elastic.co/t/help-with-ruby-code-please-using-user-input-in-searches/200545/2 "2019-10-19T19:44:52Z")

</div>

Closed on October 19, 2019, 7:44pm UTC

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