vanng822 / go-solr

Solr client in Go, core admin, add docs, update, delete, search and more
MIT License
69 stars 42 forks source link

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

Open msonawane opened 4 years ago

msonawane commented 4 years ago

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 .

vanng822 commented 4 years ago

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