【问题标题】:Elasticsearch UpdateByQuery index refresh issueElasticsearch UpdateByQuery 索引刷新问题
【发布时间】:2018-10-12 20:14:06
【问题描述】:

我在 C# 上使用 Elasticsearch(ES) 5 和 NEST 5

我有一个使用 ES 实现的工作流。简化工作流程有 2 个步骤。

第 1 步:我根据某些条件使用 UpdateByQuery 语句生成消息的收件人。

第 2 步:我查询第 1 步生成的所有收件人以实际传递消息。

我面临的问题是,有时第一步运行得太快,以至于当第二步运行时索引尚未刷新,因此找不到收件人。

我尝试设置“WaitForCompletion(true)”(Nest 上的默认设置)但我得到了相同的结果。我还注意到 UpdateByQuery 不支持 refresh=wait_for 所以不知道该怎么做。

我的查询更新如下所示:

query
.Index(allIndexesStr)

// Exclude all contact in this list
.Query(q =>
    ...
)
.WaitForCompletion(true)
// Update script
.Script(script => script
    .Inline(scriptStr)
    .Params(p =>
        ...
    )
)
.Routing(customerSiteId.ToString());

我的搜索如下所示:

search
.Index(allIndexesStr)
.Size(size)
.Scroll(timeout)
.Query(q =>
    ...
)
.Sort(sort => sort
    .Ascending("contactGuid.keyword")
)
.Routing(customerSiteId.ToString());

所以我想知道如何使用 ES 解决这个问题的正确方法...

任何帮助将不胜感激

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    如果你分两步做,那么你应该这样做

    var result = ...
                .Index(allIndexesStr)
    
            // Exclude all contact in this list
            .Query(q =>
                ...
            )
            .WaitForCompletion(true)
            // Update script
            .Script(script => script
                .Inline(scriptStr)
                .Params(p =>
                    ...
                )
            )
            .Refresh(true)
            .Routing(customerSiteId.ToString());
    
    if (result.IsValid)
    {
        search
        .Index(allIndexesStr)
        .Size(size)
        .Scroll(timeout)
        .Query(q =>
        ...
        )
        .Sort(sort => sort
            .Ascending("contactGuid.keyword")
        )
        .Routing(customerSiteId.ToString());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      • 2017-03-26
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 2023-03-10
      • 2020-03-27
      相关资源
      最近更新 更多