我使用 olivere elastic library连接到弹性。 所以我有一个客户端,连接它,添加一些文件。 然后我有另一个进行搜索的客户。但我必须等待几秒钟,因为即时响应是空的
_, err := client.Index().
Index(elasticTemplateName).
Type(elasticType).
Id(myID).
BodyJson(myJson).
Do(ctx)
require.NoError(t, err)
// wait cause of async elastic client
time.Sleep(1000 * time.Millisecond)
result, err := anotherClient.Search().Index(IndexName).SearchSource(searchSource).Do(ctx)
另一个客户:
client, err := elastic.NewClient(
elastic.SetURL(
conf.Hosts...
),
elastic.SetSniff(false),
)
最佳答案
您可能想使用刷新 API,请参阅 https://github.com/olivere/elastic/blob/release-branch.v6/indices_refresh.go
插入是实时的,但 get 使用的索引不是
关于elasticsearch - Go弹性客户端: have to wait some time before run query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52498734/