elasticsearch - 戈朗 : How to construct a struct for Elasticsearch pipeline attachment

标签 elasticsearch go

我正在构建一个结构来将 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 用于处理器并作为带有描述的附件结构进行舍入.

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

谢谢!

最佳答案

我能成功做到这一点,

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

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}

关于elasticsearch - 戈朗 : How to construct a struct for Elasticsearch pipeline attachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44390244/

相关文章:

elasticsearch - 在 ElasticSearch 中启用搜索慢日志

pointers - 我如何从golang中的 slice 获取结构指针

go - 将结构内容复制到 Go 中的 uint64

elasticsearch - 有什么方法可以用 elasticsearch 的 kibana 安装 kibana?

mysql - 从elasticsearch、mysql、google Analytics、日志获取数据并创建统计数据

elasticsearch - 在elasticsearch中创建索引时自定义分析器的mapper_parsing_exception?

boost - 在Elasticsearch中,如何 boost 某些领域?

go - 使 marshar 从字符串失败

mysql - 如何在 MySQL 中存储二进制数据?

docker - 如何在 Dockerfile 中使用 ENTRYPOINT 执行 Docker 容器