title: create elasticsearch query with optional params
body: <p>I'm trying to create an elasticsearch query that have the following logic: search by title, and if the type of record is given, also add it to the query. I did this</p>
  
  <pre><code>  def to_es_query
      {
        query: {
          match: {
            title_en: { query: @title }
          }.merge!(optional_params)
        }
      }
    end
  
    def optional_params
      type_param
    end
  
    def type_param
      return {} unless @type
      {
        match: {
          type: {
            query: @type
          }
        }
      }
    end
  </code></pre>
  
  <p>What i'm doing wrong?</p>