英文:
Elasticsearch Point In Time Request API in Golang
问题
我正在尝试使用官方的go-elasticsearch库,在golang中使用点在时间(Point in Time)API。我似乎找不到任何解释如何使用它的文档。
我已经能够创建一个OpenPointInTime
对象并检索到一个PIT id。我无法弄清楚该如何使用它,或者在elasticsearch.Client.Search
函数中放置它的位置。我也没有找到示例。
有人可以给出一个使用官方库的基本示例吗?
英文:
I'm trying to use the point in time api in golang using the official go-elasticsearch library. I can't seem to find any documentation that explains how to use it.
I've been able to create a OpenPointInTime
object and retrieve a PIT id. I can't figure out what to do with it or where to place it in the elasticsearch.Client.Search
function. I haven't been able to to find an example either.
Can anyone give a basic example using the official library.
答案1
得分: 1
在浏览了elasticsearch库的GitHub存储库上的已关闭问题后,我找到了这个问题线程:https://github.com/elastic/go-elasticsearch/issues/234
根据这个线程,我需要从OpenPointInTime
响应中获取一个PIT id,并将其添加到请求体中。
以下代码对我有效:
var query_buffer bytes.Buffer
body := `
{
"query": {
"term": {
"_id": "AkUN7YUB2JzVdyKtJ8bD"
}
},
"pit": {
"id": "your pit id here",
"keep_alive": "3m"
}
}
`
es, _ := elasticsearch.NewDefaultClient()
json.NewDecoder(&query_buffer).Decode(&body)
res, err := es.Search(
es.Search.WithAllowPartialSearchResults(true),
es.Search.WithBody(&query_buffer),
)
请注意,这只是一个示例代码片段,具体的实现可能因你的需求而有所不同。
英文:
After going through the closed issues on the github repo of the elasticsearch library, I found this issue thread: https://github.com/elastic/go-elasticsearch/issues/234
According to this thread, I need to get a PIT id from OpenPointInTime
response and add it to the body.
This worked for me:
var query_buffer bytes.Buffer
body := `
{
"query": {
"term": {
"_id": "AkUN7YUB2JzVdyKtJ8bD"
}
},
"pit": {
"id": "your pit id here",
"keep_alive": "3m"
}
}
`
es, _ := elasticsearch.NewDefaultClient()
json.NewDecoder(&query_buffer).Decode(&body)
res, err := es.Search(
es.Search.WithAllowPartialSearchResults(true),
es.Search.WithBody(&query_buffer),
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论