|
|
@@ -13,6 +13,7 @@ import ( |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"reflect" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
) |
|
|
@@ -139,13 +140,25 @@ func (c *Connection) BulkSend(documents []Document) (Response, error) { |
|
|
|
bulkData[i] = action |
|
|
|
i++ |
|
|
|
|
|
|
|
if len(doc.Fields) > 0 { |
|
|
|
fields := make(map[string]interface{}, len(doc.Fields)) |
|
|
|
for fieldName, fieldValue := range doc.Fields { |
|
|
|
fields[fieldName] = fieldValue |
|
|
|
if doc.Fields != nil { |
|
|
|
if docFields, ok := doc.Fields.(map[string]interface{}); ok { |
|
|
|
if len(docFields) == 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
} else { |
|
|
|
typeOfFields := reflect.TypeOf(doc.Fields) |
|
|
|
if typeOfFields.Kind() == reflect.Ptr { |
|
|
|
typeOfFields = typeOfFields.Elem() |
|
|
|
} |
|
|
|
if typeOfFields.Kind() != reflect.Struct { |
|
|
|
return Response{}, fmt.Errorf("Document fields not in struct or map[string]interface{} format") |
|
|
|
} |
|
|
|
if typeOfFields.NumField() == 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sources, err := json.Marshal(fields) |
|
|
|
sources, err := json.Marshal(doc.Fields) |
|
|
|
if err != nil { |
|
|
|
return Response{}, err |
|
|
|
} |
|
|
|