问题如标题。
我已经按照文档的说明来进行操作了,但是还是提示错误。求解。谢谢。
https://www.bookstack.cn/read/elasticsearch-definitive-guide-cn/030_Data-55_Bulk.md
package main
import (
"fmt"
"strings"
"github.com/astaxie/beego/httplib"
)
func main() {
api := "http://localhost:9200/_bulk"
body := []string{
`{ "index": { "_index": "testbulk", "_type": "fulltext","_id":1 }}`,
`{ "title": "My second blog post 1" }`,
`{ "index": { "_index": "testbulk", "_type": "fulltext","_id":2 }}`,
`{ "title": "My second blog post 2" }`,
`{ "index": { "_index": "testbulk", "_type": "fulltext","_id":3 }}`,
`{ "title": "My second blog post 3" }`,
}
str := strings.Join(body, "\n")
fmt.Println(str)
resp, err := httplib.Post(api).Header("Content-Type", "application/json").Body(str).String()
fmt.Println(resp, err)
}
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"}],"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"},"status":400} <nil>