This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es): Handle the problem that the batch method in version 8.* retu…
…rns an IsValid error (#85)
- Loading branch information
1 parent
fb11a69
commit eaead31
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,4 +540,32 @@ public async Task ClearDocumentAsync() | |
|
||
await _builder.Client.DeleteIndexByAliasAsync(alias); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TestAsync() | ||
{ | ||
string userIndexName = $"user_index"; | ||
|
||
IServiceCollection service = new ServiceCollection(); | ||
var builder = service.AddElasticsearchClient("es", "http://localhost:9200"); | ||
await builder.Client.DeleteIndexAsync(userIndexName); | ||
var serviceProvider = builder.Services.BuildServiceProvider(); | ||
var client = serviceProvider.GetRequiredService<IMasaElasticClient>(); | ||
|
||
var list = new AutoCompleteDocument<long>[] | ||
{ | ||
new() | ||
{ | ||
Text = "[email protected]", | ||
Value = 1 | ||
} | ||
}; | ||
var request = new SetDocumentRequest<AutoCompleteDocument<long>>(userIndexName); | ||
foreach (var document in list) | ||
request.AddDocument(document, document.Id); | ||
|
||
var response = await client.SetDocumentAsync(request, default); | ||
Assert.IsTrue(response.IsValid); | ||
await builder.Client.DeleteIndexAsync(userIndexName); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/Masa.Utils.Data.Elasticsearch.Tests/Models/AutoCompleteDocument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Utils.Data.Elasticsearch.Tests.Models; | ||
|
||
public class AutoCompleteDocument<TValue> where TValue : notnull | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Text { get; set; } | ||
|
||
public TValue? Value { get; set; } | ||
|
||
public AutoCompleteDocument() | ||
{ | ||
} | ||
|
||
public AutoCompleteDocument(string text, TValue? value) | ||
: this(value?.ToString() ?? throw new ArgumentException($"{value} cannot be empty", nameof(value)), text, value) | ||
{ | ||
} | ||
|
||
public AutoCompleteDocument(string id, string text, TValue? value) : this() | ||
{ | ||
Id = id; | ||
Text = text; | ||
Value = value; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters