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

时间:2017-06-06 12:38:50

标签: elasticsearch go

我构建一个结构来向Elasticsearch发送put消息以获取管道附件。

这是我应该将它发送给ES的json:

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

我是否真的需要制作一个结构并编组它以便发布消息? (我来自Python)。设置管道是一个单一的过程。

我在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"`
}

如果您可以看到代码,我就会停留在ASP structAS struct 处理器,并将其作为附件结构与说明进行四舍五入。

有人可以指导我吗?我甚至不确定我是否对上述结构是正确的。

谢谢!

2 个答案:

答案 0 :(得分:0)

我能够成功地完成这项工作,

我构造了这样的结构:

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

然后我发送了一个类似于此的put请求 https://github.com/DaddyOh/golang-samples/blob/master/httpClient.go

我得到了结果:

{"acknowledged":true}

答案 1 :(得分:0)

您可以使用具有弹性搜索挂钩的logrus包,并且非常简单。

相关问题