title: How do you convert an Elasticsearch JSON String Response, with an Aggregation, to an Elasticsearch SearchResponse Object
body: <p>I want to serialize a json string to an Elasticsearch SearchResponse object. It works fine if the json string doesn't contains an aggregation. </p>
  
  <p>If the json string contains an aggregation the XContentParser throws an 
  <i>ParsingException[Could not parse aggregation keyed as [target_field]</i> 
  exception.</p>
  
  <p>The code I use to serialize the json string to an Elasticsearch SearchResponse object: </p>
  
  <pre><code>    Settings settings = Settings.builder().build();
      SearchModule searchModule = new SearchModule(settings, false, new ArrayList&lt;&gt;());
  
      NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
  
      JsonXContentParser xContentParser = new JsonXContentParser(xContentRegistry,
              new JsonFactory().createParser(json));
      SearchResponse response = SearchResponse.fromXContent(xContentParser);
  </code></pre>
  
  <p>It seems that I have to register aggregations to the NamedXContentRegistry but i don't know how to. </p>