0

i am trying to save list of maps contents to elastic search(as nested type)and it is failing. sample code is below import ( "fmt" )

func main() {
    fmt.Println("Hello, playground")
    var List_CounterData []interface{}
    List_Counterdata = map[string]interface{}{}
    err := savekpi(List_Counterdata)
    if err != nil {
    fmt.Println("error in save")
    }   
}

func saveKpi(kpi interface{}) error {
    put1, err := elasticSearchClient.Index().
        Index(KpiIndex).
        Type(KpiDocType).
        Id("1001").
        BodyJson(kpi).
        Do(elasticSearchContext)
    if err != nil {
        fmt.Println("Failed to store Kpi , %v", err.Error())
        return err
    }
    fmt.Println("Indexed  %s to index %s, type %s\n", put1.Id, put1.Index, put1.Type)
    return err
}

My List_Counterdata sample is below

List_Counterdata = [map[name: kisha] map[name: kish age: 29]]

When trying to create index, following the error

elastic: Error 400 (Bad Request): failed to parse [type=mapper_parsing_exception]
kish
  • 545
  • 2
  • 5
  • 11
  • What does your index mapping look like? Are you sure `List_CounterData` has what you expect? Where are `KpiIndex` and `KpiDocType` defined? – Cfreak Feb 27 '18 at 17:28
  • Hi Please find the declaration const RegisterIndex = "register" const KpiIndex = "kpi" // Register & Kpi Index doc type const RegisterDocType = "register" const KpiDocType = "kpi" const KpiMapping = ` { "mappings": { "kpi": { "properties": { "kpi": { "type": "nested" } } } } }` – kish Feb 27 '18 at 17:34
  • @Cfreak above is the data type declarations – kish Feb 28 '18 at 06:53

0 Answers0