elasticsearch - Go弹性客户端: have to wait some time before run query

标签 elasticsearch go

我使用 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/

相关文章:

Elasticsearch 日期直方图

elasticsearch - 范围过滤器-接受每个日期

elasticsearch - 为什么kibana 3.x无法与 Elasticsearch 2.x一起使用?

mongodb - 无法创建/访问数据库

json - 想要发送空 json 字符串 "{}"而不是 "null"

sockets - 在封闭的net.Conn上写入,但返回nil错误

html - 如何将 html 表单中的日期和时间输入类型存储到 sqlite3 DB 中

Elasticsearch:如何将嵌套的 Json 数组对象插入到 Elasticsearch 索引中

go - Go 中的惯用过滤错误

sorting - 对Elasticsearch日期字段进行基于脚本的排序