How to resolve Elasticsearch client method not recognized error message in Go?

王林
Release: 2024-02-09 08:21:32
forward
765 people have browsed it

如何解决 Go 中无法识别 Elasticsearch 客户端方法的错误消息?

When php editor Xiaoxin writes an application using Go language, he may encounter an error message that the Elasticsearch client method cannot be recognized. This may be caused by missing necessary dependencies or configuration issues. In order to solve this problem, there are several steps that can be taken: 1. Make sure that the Elasticsearch client library has been installed correctly. You can install the latest version of the client library by using the go get command, for example: go get github.com/olivere/elastic/v7. 2. Make sure the Elasticsearch client library is correctly imported in the code. Check whether the import statement is correct, for example: import "github.com/olivere/elastic/v7". 3. Check the initial configuration of the Elasticsearch client. Make sure you pass in the correct Elasticsearch server address and port number, as well as other necessary configuration information when initializing the client. 4. Check whether the method call is correct. Make sure you use the correct method name and parameters when calling methods on the Elasticsearch client. By checking and adjusting the above steps, you should be able to solve the error message that the Elasticsearch client method cannot be recognized. If the problem persists, you can consult the official documentation or seek help in the relevant development community.

Question content

I am trying to perform a search on the elasticsearch client in go (olivere/elastic) using the corresponding client library for elasticsearch version 7.x. The expected behavior is that the code compiles without errors and returns scrollable search results with the specified query, aggregation, size, track total hits, pretty, and sorting options.

However, the actual behavior generates an error message stating that the aggregation, size, tracktotalhits, pretty, sort and do methods are not recognized. This error message may indicate a problem with the syntax or references of elasticsearch client methods.

Can anyone suggest steps to resolve this issue and help me resolve the error? Also, please find below the code I'm currently using:

searchResult, err := r.elasticClient.
    Scroll().
    Index(r.index).
    Query(query).
    Aggregation("agg", agg).
    Size(limit).
    TrackTotalHits(true).
    Pretty(true).
    Sort("startTime", true).
    Do(context.Background())
Copy after login

thanks for your help!

Workaround

The scrolling API is for scrolling through documents, not aggregations. refer to.

The above is the detailed content of How to resolve Elasticsearch client method not recognized error message in Go?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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