dongluni0568 2017-06-06 12:38
浏览 121
已采纳

Golang:如何为Elasticsearch管道附件构建结构

I'm constructing a struct to send a put message to Elasticsearch for pipeline attachment.

This is the json that I'm supposed to send it to ES:

PUT _ingest/pipeline/attachment 
{   
    "description": "Process documents",   
    "processors": [
        {
            "attachment": {
                "field": "thedata",
                "indexed_chars": -1
            }
        },
        {
            "set": {
                "field": "attachment.title",
                "value": "{{ title }}"
            }
        },
        {
            "set": {
                "field": "attachment.author",
                "value": "{{ author }}"
            }
        },
        {
            "set": {
                "field": "attachment.url",
                "value": "{{ url }}"
            }
        },
        {
            "set": {
                "field": "attachment.cover",
                "value": "{{ cover }}"
            }
        },
        {
            "set": {
                "field": "attachment.page",
                "value": "{{ page }}"
            }
        }
    ] 
}

Do I really need to make a struct and marshal it in order to put the message? (I'm coming from Python). Setting up pipeline is a single time process.

I'm constructing structs like this in Go:

type AS struct {
    Description string

}

type ASP struct {
    Processors 
}

type ASPA struct {
    Attachment []ASPAF `json:"attachment"`
}

type ASPAF struct {
    Field string `json:"field"`
    IndexedChars uint64 `json:"indexed_chars"`
}

type ASPS struct {
    Set []ASPSF `json:"set"`
}

type ASPSF struct {
    Field string `json:"field"`
    Value string `json:"value"`
}

If you can see the code, I'm stuck at ASP struct and AS struct for processors and rounding up as attachment struct with description.

Could someone guide me? I'm not even sure if I'm right with the above structs.

Thanks!

  • 写回答

2条回答 默认 最新

  • dst2007 2017-06-06 14:44
    关注

    I'm able to do this successfully,

    I have constructed structs like this:

    type AS struct {
        Description string `json:"description"`
        Processors []ASP `json:"processors"`
    }
    
    type ASP struct {
        Attachment ASPA `json:"attachment"`
    }
    
    type ASPA struct {
        Field string `json:"field"`
        IndexedChars int64 `json:"indexed_chars"`
    }
    
    attachment := &AS{
        Description: "Process documents",
        Processors: []ASP{
            ASP{
                Attachment: ASPA{
                    Field: "thedata",
                    IndexedChars: -1,
                },
            },
        },
    }
    

    Then I sent a put request similar to this https://github.com/DaddyOh/golang-samples/blob/master/httpClient.go

    I got the result:

    {"acknowledged":true}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了