Buggy code:
@ Override public String sourceAsString ( ) { } @ Override public String getSourceAsString ( ) { } @ SuppressWarnings ( { "unchecked" } ) @ Override public Map < String , Object > sourceAsMap ( ) throws ElasticsearchParseException { } @ Override public Iterator < SearchHitField > iterator ( ) { } @ Override public SearchHitField field ( String fieldName ) { } @ Override public Map < String , SearchHitField > fields ( ) { } public Map < String , SearchHitField > fieldsOrNull ( ) { } @ Override public Map < String , SearchHitField > getFields ( ) { } public void fields ( Map < String , SearchHitField > fields ) { } public Map < String , HighlightField > internalHighlightFields ( ) { } @ Override public Map < String , HighlightField > highlightFields ( ) { } @ Override public Map < String , HighlightField > getHighlightFields ( ) { } public void highlightFields ( Map < String , HighlightField > highlightFields ) { } public void sortValues ( Object [ ] sortValues ) { } @ Override public Object [ ] sortValues ( ) { } @ Override public Object [ ] getSortValues ( ) { } @ Override public Explanation explanation ( ) { } @ Override public Explanation getExplanation ( ) { } public void explanation ( Explanation explanation ) { } @ Override public SearchShardTarget shard ( ) { } @ Override public SearchShardTarget getShard ( ) { } public void shard ( SearchShardTarget target ) { } public void matchedQueries ( String [ ] matchedQueries ) { } @ Override public String [ ] matchedQueries ( ) { } @ Override public String [ ] getMatchedQueries ( ) { } public static class Fields { static final XContentBuilderString _INDEX = new XContentBuilderString ( "_index" ) ; static final XContentBuilderString _TYPE = new XContentBuilderString ( "_type" ) ; static final XContentBuilderString _ID = new XContentBuilderString ( "_id" ) ; static final XContentBuilderString _VERSION = new XContentBuilderString ( "_version" ) ; static final XContentBuilderString _SCORE = new XContentBuilderString ( "_score" ) ; static final XContentBuilderString FIELDS = new XContentBuilderString ( "fields" ) ; static final XContentBuilderString HIGHLIGHT = new XContentBuilderString ( "highlight" ) ; static final XContentBuilderString SORT = new XContentBuilderString ( "sort" ) ; static final XContentBuilderString MATCHED_QUERIES = new XContentBuilderString ( "matched_queries" ) ; static final XContentBuilderString _EXPLANATION = new XContentBuilderString ( "_explanation" ) ; static final XContentBuilderString VALUE = new XContentBuilderString ( "value" ) ; static final XContentBuilderString DESCRIPTION = new XContentBuilderString ( "description" ) ; static final XContentBuilderString DETAILS = new XContentBuilderString ( "details" ) ; } @ Override public XContentBuilder toXContent ( XContentBuilder builder , Params params ) throws IOException { builder . startObject ( ) ; if ( ( explanation ( ) ) != null ) { builder . field ( "_shard" , shard . shardId ( ) ) ; builder . field ( "_node" , shard . nodeIdText ( ) ) ; } builder . field ( InternalSearchHit . Fields . _INDEX , shard . indexText ( ) ) ; builder . field ( InternalSearchHit . Fields . _TYPE , type ) ; builder . field ( InternalSearchHit . Fields . _ID , id ) ; if ( ( version ) != ( - 1 ) ) { builder . field ( InternalSearchHit . Fields . _VERSION , version ) ; } if ( Float . isNaN ( score ) ) { builder . nullField ( InternalSearchHit . Fields . _SCORE ) ; } else { builder . field ( InternalSearchHit . Fields . _SCORE , score ) ; } if ( ( source ) != null ) { XContentHelper . writeRawField ( "_source" , source , builder , params ) ; } if ( ( ( fields ) != null ) && ( ! ( fields . isEmpty ( ) ) ) ) { builder . startObject ( InternalSearchHit . Fields . FIELDS ) ; for ( SearchHitField field : fields . values ( ) ) { if ( field . values ( ) . isEmpty ( ) ) { continue ; } String fieldName = field . getName ( ) ; if ( field . isMetadataField ( ) ) { <START_BUG> builder . field ( fieldName , field . value ( ) ) ; <END_BUG> } else { builder . startArray ( fieldName ) ; for ( Object value : field . getValues ( ) ) { builder . value ( value ) ; } builder . endArray ( ) ; } } builder . endObject ( ) ; } if ( ( ( highlightFields ) != null ) && ( ! ( highlightFields . isEmpty ( ) ) ) ) { builder . startObject ( InternalSearchHit . Fields . HIGHLIGHT ) ; for ( HighlightField field : highlightFields . values ( ) ) { builder . field ( field . name ( ) ) ; if ( ( field . fragments ( ) ) == null ) { builder . nullValue ( ) ; } else { builder . startArray ( ) ; for ( Text fragment : field . fragments ( ) ) { builder . value ( fragment ) ; } builder . endArray ( ) ; } } builder . endObject ( ) ; } if ( ( ( sortValues ) != null ) && ( ( sortValues . length ) > 0 ) ) { builder . startArray ( InternalSearchHit . Fields . SORT ) ; for ( Object sortValue : sortValues ) { if ( ( sortValue != null ) && ( sortValue . equals ( InternalSearchHit . MAX_TERM_AS_TEXT ) ) ) { builder . nullValue ( ) ; } else { builder . value ( sortValue ) ; } } builder . endArray ( ) ; } if ( ( matchedQueries . length ) > 0 ) { builder . startArray ( InternalSearchHit . Fields . MATCHED_QUERIES ) ;

Fix:
builder . field ( fieldName , ( ( Object ) ( field . value ( ) ) ) ) ;