title: Golang to elastic- build dynamic query
body: <p>I'm new to Goleng and Elastic.
  I have a static query that I took out of the Kibana, now I want to use this query to build a dynamic query code according to the parameters that the customer will send</p>
  <p>how i add or remove &quot;event_state.status&quot; according  to user parameters.
  how i convert this json to <code>map[string]interface {}</code>.
  The client package i was use its <a href="https://github.com/elastic/go-elasticsearch" rel="nofollow noreferrer">https://github.com/elastic/go-elasticsearch</a></p>
  <p>this is the json query :</p>
  <pre><code>{
    &quot;sort&quot;: [
      {
        &quot;@timestamp&quot;: {
          &quot;order&quot;: &quot;desc&quot;,
          &quot;unmapped_type&quot;: &quot;boolean&quot;
        }
      }
    ],
    &quot;from&quot;: 0,
    &quot;size&quot;: 10000,
    &quot;query&quot;: {
      &quot;bool&quot;: {
        &quot;filter&quot;: [
          {
            &quot;bool&quot;: {
              &quot;filter&quot;: [
                {
                  &quot;bool&quot;: {
                    &quot;should&quot;: [
                      {
                        &quot;match_phrase&quot;: {
                          &quot;webhook_id&quot;: &quot;12345&quot;
                        }
                      }
                    ],
                    &quot;minimum_should_match&quot;: 1
                  }
                },
                {
                  &quot;bool&quot;: {
                    &quot;should&quot;: [
                      {
                        &quot;bool&quot;: {
                          &quot;should&quot;: [
                            {
                              &quot;match&quot;: {
                                &quot;event_state.status&quot;: &quot;rejected&quot;
                              }
                            }
                          ],
                          &quot;minimum_should_match&quot;: 1
                        }
                      },
                      {
                        &quot;bool&quot;: {
                          &quot;should&quot;: [
                            {
                              &quot;match&quot;: {
                                &quot;event_state.status&quot;: &quot;succeeded&quot;
                              }
                            }
                          ],
                          &quot;minimum_should_match&quot;: 1
                        }
                      },
                      {
                        &quot;bool&quot;: {
                          &quot;should&quot;: [
                            {
                              &quot;match&quot;: {
                                &quot;event_state.status&quot;: &quot;expired&quot;
                              }
                            }
                          ],
                          &quot;minimum_should_match&quot;: 1
                        }
                      },
                      {
                        &quot;bool&quot;: {
                          &quot;should&quot;: [
                            {
                              &quot;match&quot;: {
                                &quot;event_state.status&quot;: &quot;inactive&quot;
                              }
                            }
                          ],
                          &quot;minimum_should_match&quot;: 1
                        }
                      }
                    ],
                    &quot;minimum_should_match&quot;: 1
                  }
                }
              ]
            }
          },
          {
            &quot;range&quot;: {
              &quot;created_at&quot;: {
                &quot;format&quot;: &quot;strict_date_optional_time&quot;,
                &quot;gte&quot;: &quot;2022-02-16T03:19:50.267Z&quot;,
                &quot;lte&quot;: &quot;2022-02-17T03:19:50.267Z&quot;
              }
            }
          }
        ]
      }
    },
    &quot;collapse&quot;: {
      &quot;field&quot;: &quot;uuid.keyword&quot;,
      &quot;inner_hits&quot;: {
        &quot;name&quot;: &quot;order by attempt_count&quot;,
        &quot;size&quot;: 1,
        &quot;sort&quot;: [
          {
            &quot;event_state.attempt_count&quot;: &quot;desc&quot;
          }
        ]
      }
    }
  }
  </code></pre>