go-solr icon indicating copy to clipboard operation
go-solr copied to clipboard

how to go about inserting []jsonDocs ( Update() returns success but solr logs show failures)

Open msonawane opened this issue 4 years ago • 1 comments

I already have json docs as string

following code snippet is used to construct a valid json string.

func StoreInSolr(sc *solr.SolrInterface, docs []string) (*solr.SolrUpdateResponse, error) {
	params := &url.Values{}
	params.Add("commit", "true")
	var lines []string
	for _, doc := range docs {
		if len(strings.TrimSpace(doc)) == 0 {
			continue
		}
		lines = append(lines, doc)
	}
	data := fmt.Sprintf("[%s]\n", strings.Join(lines, ","))
	fmt.Printf("data: %+v\n", data)
	resp, err := sc.Update(data, params)
	return resp, err
}
both resp and err indicate success:
&solr.SolrUpdateResponse{Success:true, Result:map[string]interface {}{"responseHeader":map[string]interface {}{"QTime":3, "status":0}}}, err: <nil>

but on solr debug logs i get

o.a.s.h.l.JsonLoader Can't have a value here. Unexpected STRING at [1]

This has to do with json string format but json is valid.

any pointers appreciated .

msonawane avatar Feb 28 '20 11:02 msonawane

Hi @msonawane It is long time ago I use Solr. I use responseHeader.status as success indicator and can not answer why solr return 0 instead of 400. Don't know if any other here can answer that question? else more likely you can find the answer at Solr-project itself. Do you have entire response from Solr? How come that you have it as string already?

Else maybe this can help you? https://github.com/vanng822/go-solr/blob/master/solr/solr.go#L170 https://github.com/vanng822/go-solr/blob/master/solr/solr.go#L162

vanng822 avatar Feb 29 '20 09:02 vanng822