Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
fix(es): Handle the problem that the batch method in version 8.* retu…
Browse files Browse the repository at this point in the history
…rns an IsValid error (#85)
  • Loading branch information
zhenlei520 authored Jul 14, 2022
1 parent fb11a69 commit eaead31
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MicrosoftTeskSdkPackageVersion>16.9.4</MicrosoftTeskSdkPackageVersion>
<CoverletPackageVersion>3.0.2</CoverletPackageVersion>
<MoqPackageVersion>4.16.1</MoqPackageVersion>
<NESTPackageVersion>7.16.0</NESTPackageVersion>
<NESTPackageVersion>7.17.4</NESTPackageVersion>
<NpgsqlPackageVersion>6.0.1</NpgsqlPackageVersion>
<GrpcNetPackageVersion>2.40.0</GrpcNetPackageVersion>
<DaprPackageVersion>1.5.0</DaprPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private IElasticClient Create(string name)

private ConnectionSettings GetConnectionSettingsBySingleNode(ElasticsearchRelations relation)
{
var connectionSetting = new ConnectionSettings(relation.Nodes[0]);
var connectionSetting = new ConnectionSettings(relation.Nodes[0])
.EnableApiVersioningHeader();
relation.Action?.Invoke(connectionSetting);
return connectionSetting;
}
Expand All @@ -74,7 +75,8 @@ private ConnectionSettings GetConnectionSettingsConnectionPool(ElasticsearchRela
pool,
relation.ConnectionSettingsOptions?.Connection,
relation.ConnectionSettingsOptions?.SourceSerializerFactory,
relation.ConnectionSettingsOptions?.PropertyMappingProvider);
relation.ConnectionSettingsOptions?.PropertyMappingProvider)
.EnableApiVersioningHeader();

relation.Action?.Invoke(settings);
return settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
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;
}
}

1 change: 1 addition & 0 deletions test/Masa.Utils.Data.Elasticsearch.Tests/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
global using Masa.Utils.Data.Elasticsearch.Options.Document.Set;
global using Masa.Utils.Data.Elasticsearch.Options.Document.Update;
global using Masa.Utils.Data.Elasticsearch.Options.Index;
global using Masa.Utils.Data.Elasticsearch.Tests.Models;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using Nest;
Expand Down

0 comments on commit eaead31

Please sign in to comment.