Failed to save list of maps content to elasticsearch


(kish) #1

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

import (
"fmt"
)

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" } } } } }

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) #2

any clue?


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.