【问题标题】:Golang: How to construct a struct for Elasticsearch pipeline attachmentGolang:如何为 Elasticsearch 管道附件构建结构
【发布时间】:2017-11-07 11:37:32
【问题描述】:

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

这是我应该发送给 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 处理器和四舍五入作为带有描述的附件结构

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

谢谢!

【问题讨论】:

    标签: elasticsearch go


    【解决方案1】:

    我能够成功地做到这一点,

    我已经构建了这样的结构:

    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}
    

    【讨论】:

      【解决方案2】:

      你可以使用logrus 包,它有弹性搜索钩子,很简单。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-06
        • 1970-01-01
        • 2020-05-19
        • 1970-01-01
        • 2016-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多