如何在elasticsearch golang客户端中检索整个搜索命中源?

I have an index with too many fields like one docs has 6 fields and other has different number of fields, together there are nearly thousand different fields on total.

i followed this https://github.com/olivere/elastic/wiki/Search, it works fine but i cannot create a struct of all the fields and do json.Unmarshal(*hit.Source, &t) on that. is there any way i can retrieve entire source with out the fields struct.

i use elasticsearch version -7 and olivre elasticsearch golang library.

If I understand correctly, you do not want to unmarshal the json result - you just want access to the value.

The search operation returns a SearchHit result docs here

Which has a field

type SearchHit struct {
    // trimmed
    Source         json.RawMessage                `json:"_source,omitempty"`         

}

A json.RawMessage is just a []byte, docs here.

So to get it as a string, you could do:

s := string(hit.Source)