Home > Article > Backend Development > Elasticsearch point-in-time request API in Golang
In Golang, Elasticsearch is a very popular distributed search and analysis engine. It has powerful functions and flexible query language to meet various data retrieval needs. Among them, the time point request API is an important feature of Elasticsearch, which allows us to retrieve and aggregate data according to time range. In this article, PHP editor Xinyi will introduce in detail the usage and precautions of the Elasticsearch time point request API in Golang to help readers better understand and apply this function.
I am trying to use the point-in-time api in golang using the official go-elasticsearch library. I can't seem to find any documentation explaining how to use it.
I have been able to create the OpenPointInTime
object and retrieve the PIT id. I don't know how to handle it or where to place it in the elasticsearch.Client.Search
function. I can't find an example either.
Can anyone give a basic example using the official library.
After browsing the closed issues on the elasticsearch library's github repository, I found this issue thread: https://www.php.cn/ link/4bdb6179647296e518bd72e62d3bf5c1
According to this thread, I need to get the pit id from the 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), )
The above is the detailed content of Elasticsearch point-in-time request API in Golang. For more information, please follow other related articles on the PHP Chinese website!