Elasticsearch point-in-time request API in Golang

王林
Release: 2024-02-13 15:39:21
forward
871 people have browsed it

Golang 中的 Elasticsearch 时间点请求 API

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.

Question content

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.

Solution

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),
)
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!