我正在构建一个结构来将 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 struct
和 AS 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/