[英]Calling Search immediately after indexing fails intermittently in Elasticsearch NEST
我正在使用NEST
Elasticsearch
客戶端並嘗試進行單元測試。 我看到 GET 立即開始工作,但 SEARCH 需要幾毫秒,導致測試間歇性失敗。
await _elasticClient.GetAsync<User>(id)).Source; //Works fine
elasticClient.Search<User>(s =>
s.Query(q =>
q.MultiMatch(x =>
x.Fields(f => f
.Field(petType => petType.Name, 3)
.Field(petType => petType.Category)
)));
// response.Documents is empty many times.
在 Index 和 Search 語句之間添加 500 毫秒的延遲是可行的,但會使測試變慢。
有沒有辦法解決這個問題。
我相信搜索遵循最終一致性。 我將嘗試將副本數或分片數配置為 1,看看是否有幫助。
我通過調用 Refresh API 解決了這個問題。
await _client.Indices.RefreshAsync("index-name");
刷新等待索引完成。 這個答案可以參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.