title: Parsing elasticsearch response
body: <p><strong>TL;DR</strong></p>
  <p>Please suggest some strategy which would not alter state of variable being passed to nested method  calls.</p>
  <p><strong>Longer version:</strong></p>
  <p>I'm writing a code to parse elasticsearch nested aggregation response in java. There are 4 nested fields, each having terms aggregation. Query looks as such:</p>
  <pre><code>  &quot;aggs&quot;: {
      &quot;Field1&quot;: {
        &quot;terms&quot;: {
          &quot;field&quot;: &quot;field1&quot;,
          &quot;size&quot;: 1
        },
        &quot;aggs&quot;: {
          &quot;Field2&quot;: {
            &quot;terms&quot;: {
              &quot;field&quot;: &quot;field2&quot;,
              &quot;size&quot;: 2
            },
            &quot;aggs&quot;: {
              &quot;Field3&quot;: {
                &quot;terms&quot;: {
                  &quot;field&quot;: &quot;field3&quot;,
                  &quot;size&quot;: 3
                }
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>To parse data at each aggregation level, I have written separate methods, parseField1(), parseField2(), parseField3(). I'm storing each field's value in an object. So I'm creating a builder object and a list and passing them to parseField1(). This method then internally passes to parseField2(), parseField3(). In parseField3() I'm storing the built object into list.
  Here, builder and list are parameters, and I'm changing their state, which is not a good practice.
  Please suggest a good approach for same.</p>
  <p>Any reference book/link would be very helpful. Thank you!</p>