如何在golang中为嵌套数据集创建结构?

New to golang & trying to make a script for making bulk upload to Elasticsearch server. My json data set is something like this...

{
    product_displayname: "LG Stylus 2 Plus K535D (16 GB, Brown)",
    product_price: "24000.00",
    popularity: "0.00",
    barcode: "",
    exclusive_flag: "0",
    product_id: "176982",
    product_name: "Stylus 2 Plus K535D (Brown)",
    brand_name: "LG",
    brand_id: "1",
    product_spec : {
        display_spec: [{
            spec_id: "103",
            sdv: "24000",
            snv: "24000.0000"
        }, {
            spec_id: "104",
            sdv: "GSM",
            snv: "0.0000"
        }],
        filter_spec: [{
            spec_id: "103",
            sdv: "24000",
            snv: "24000.0000"
        }, {
            spec_id: "105",
            sdv: "Touch Screen",
            snv: "0.0000"
        }]
    }
}

Golang Structure I made(by refering google & other online info) for the above dataset is like this...

type Product struct {
    product_displayname string `json:"product_displayname"`
    product_price       string `json:"product_price"`
    popularity          string `json:"popularity"`
    barcode             string `json:"barcode"`
    exclusive_flag      string `json:"exclusive_flag"`
    product_id          string `json:"product_id"`
    product_name        string `json:"product_name"`
    brand_name          string `json:"brand_name"`
    brand_id            string `json:"brand_id"`
    product_spec
}

type product_spec struct {
    display_spec []display_speclist
    filter_spec []filter_speclist
}

type display_speclist struct {
    spec_id string `json:"spec_id"`
    sdv     string `json:"sdv"`
    snv     string `json:"snv"`
}

type filter_speclist struct {
    spec_id string `json:"spec_id"`
    sdv     string `json:"sdv"`
    snv     string `json:"snv"`
}

But, whenever I'm trying to use above Structure with sample data in my bulk upload script I'm getting following error

github.com/crazyheart/elastic-bulk-upload/main.go:70: syntax error: missing operand
github.com/crazyheart/elastic-bulk-upload/main.go:70: unknown escape sequence
github.com/crazyheart/elastic-bulk-upload/main.go:71: syntax error: non-declaration statement outside function body

I feel like I'm making some mistake in mapping that nested field display_spec & filter_spec in golang structure. But can't able to figure out what it is.

main.go

package main

import (
    "fmt"
    "golang.org/x/net/context"
    "gopkg.in/olivere/elastic.v5"
    "strconv"
)

type Product struct {
    ProductDisplayname string `json:"product_displayname"`
    ProductPrice string `json:"product_price"`
    Popularity string `json:"popularity"`
    Barcode string `json:"barcode"`
    ExclusiveFlag string `json:"exclusive_flag"`
    ProductID string `json:"product_id"`
    ProductName string `json:"product_name"`
    BrandName string `json:"brand_name"`
    BrandID string `json:"brand_id"`
    ProductSpec struct {
        DisplaySpec []struct {
            SpecID string `json:"spec_id"`
            Sdv string `json:"sdv"`
            Snv string `json:"snv"`
        } `json:"display_spec"`
        FilterSpec []struct {
            SpecID string `json:"spec_id"`
            Sdv string `json:"sdv"`
            Snv string `json:"snv"`
        } `json:"filter_spec"`
    } `json:"product_spec"`
}

func main() {
    // Create a context
    ctx := context.Background()

    client, err := elastic.NewClient()
    if err != nil {
        fmt.Println("%v", err)
    }

    // Bulk upload code
    n := 0
    for i := 0; i < 1000; i++ {
        bulkRequest := client.Bulk()
        for j := 0; j < 10000; j++ {
            n++
            product_data := Product{product_displayname:"LG Stylus 2 Plus K535D (16 GB, Brown)",product_price:"24000.00",popularity:"0.00",barcode:"",exclusive_flag:"0",product_id:"17698276",product_name:"Stylus 2 Plus K535D (Brown)",brand_name:"LG",brand_id:"1",product_spec:{display_spec:[{spec_id:"103",sdv:"24000",snv:"24000.0000"},{spec_id:"104",sdv:"GSM",snv:"0.0000"}],filter_spec:[{spec_id:"103",sdv:"24000",snv:"24000.0000"},{spec_id:"105",sdv:"Touch Screen",snv:"0.0000"}]} }
            req := elastic.NewBulkIndexRequest().Index("shopfront").Type("products").Id(strconv.Itoa(n)).Doc(product_data)
            bulkRequest = bulkRequest.Add(req)
        }

        bulkResponse, err := bulkRequest.Do(ctx)
        if err != nil {
            fmt.Println(err)
        }
        if bulkResponse != nil {
            fmt.Println(bulkResponse)
        }
        fmt.Println(i)
    }
}

Workflow

1.- Validate your json (the one you posted is invalid).

2.- Build a proper struct, you can help yourself using this nice tool.

For your case

The structs appears to be fine except you're not exporting the struct fields by capitalizing the initial letter (Thanks @ANisus).

This (shorted) seems more natural.

type Product struct {
    ProductDisplayname string `json:"product_displayname"`
    ProductSpec struct {
        DisplaySpec []struct {
            SpecID string `json:"spec_id"`
            Sdv string `json:"sdv"`
            Snv string `json:"snv"`
        } `json:"display_spec"`
        FilterSpec []struct {
            SpecID string `json:"spec_id"`
            Sdv string `json:"sdv"`
            Snv string `json:"snv"`
        } `json:"filter_spec"`
    } `json:"product_spec"`
}