elastic / go-elasticsearch

The official Go client for Elasticsearch
https://github.com/elastic/go-elasticsearch#go-elasticsearch
Apache License 2.0
63 stars 617 forks source link

in func BulkIndexer.Add(ctx,BulkIndexerItem) ,format of the BulkIndexerItem.Body parameters is too strict and is not explicitly stated in the documentation #907

Closed mayrainLN closed 2 months ago

mayrainLN commented 2 months ago

bulk_indexer.go

type BulkIndexerItem struct {
    Body            io.ReadSeeker
        ....
}

The data must be formatted in JSON and should not include any line breaks; otherwise, Elasticsearch will return a 400 error:

 [400 Bad Request] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]." .......

This can easily lead to misuse. It is advisable to either highlight this requirement within the body argument of BulkIndexerItem or implement automatic handling of line breaks in the Add(context.Context, BulkIndexerItem) method.