func()

in pkg/espoll/search.go [164:189]


func (h *SearchHit) UnmarshalJSON(data []byte) error {
	var searchHit struct {
		Index  string          `json:"_index"`
		ID     string          `json:"_id"`
		Score  float64         `json:"_score"`
		Source json.RawMessage `json:"_source"`
		Fields json.RawMessage `json:"fields"`
	}
	if err := json.Unmarshal(data, &searchHit); err != nil {
		return err
	}
	h.Index = searchHit.Index
	h.ID = searchHit.ID
	h.Score = searchHit.Score
	h.RawSource = searchHit.Source
	h.RawFields = searchHit.Fields
	h.Source = make(map[string]any)
	h.Fields = make(map[string][]interface{})
	if err := json.Unmarshal(h.RawSource, &h.Source); err != nil {
		return fmt.Errorf("error unmarshaling _source: %w", err)
	}
	if err := json.Unmarshal(h.RawFields, &h.Fields); err != nil {
		return fmt.Errorf("error unmarshaling fields: %w", err)
	}
	return nil
}