Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36f74cb

Browse files
authoredNov 21, 2024··
Merge pull request #7 from elastic/fix-user-agent
Fix custom user-agent and update dependencies
2 parents 9ac4029 + 5de497e commit 36f74cb

File tree

6 files changed

+125
-65
lines changed

6 files changed

+125
-65
lines changed
 

‎Directory.Packages.props

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
<PropertyGroup>
44
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
55
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
6-
<!--<CentralPackageFloatingVersionsEnabled>true</CentralPackageFloatingVersionsEnabled>-->
76
</PropertyGroup>
87
<ItemGroup>
9-
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
10-
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.26.0" />
8+
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.16.1" />
9+
<PackageVersion Include="Microsoft.SemanticKernel.Abstractions" Version="1.29.0" />
1110
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
1211
<PackageVersion Include="MinVer" Version="6.0.0" />
1312
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
1413
</ItemGroup>
1514
<ItemGroup>
16-
<!--<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.315" />-->
15+
<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.334" />
1716
</ItemGroup>
18-
</Project>
17+
</Project>

‎Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreCollectionSearchMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static ICollection<Query> BuildFilter(VectorSearchFilter? basicVectorSear
6262
filterQueries.Add(Query.Terms(new TermsQuery
6363
{
6464
Field = mapping.Value!,
65-
Term = new TermsQueryField([FieldValueFromValue(anyTagEqualToClause.Value)])
65+
Terms = new TermsQueryField([FieldValueFromValue(anyTagEqualToClause.Value)])
6666
}));
6767

6868
break;

‎Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreRecordCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public async Task<VectorSearchResults<TRecord>> VectorizedSearchAsync<TVector>(T
307307

308308
// Validate inputs.
309309

310-
if (this._propertyReader.FirstVectorPropertyName is null)
310+
if (_propertyReader.FirstVectorPropertyName is null)
311311
{
312312
throw new InvalidOperationException("The collection does not have any vector fields, so vector search is not possible.");
313313
}

‎Elastic.SemanticKernel.Connectors.Elasticsearch/MockableElasticsearchClient.cs

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
using Microsoft.SemanticKernel;
1919

20+
using ExistsRequest = Elastic.Clients.Elasticsearch.IndexManagement.ExistsRequest;
21+
2022
namespace Elastic.SemanticKernel.Connectors.Elasticsearch;
2123

2224
#pragma warning disable CA1852 // TODO: Remove after using MockableElasticsearchClient in unit tests
@@ -27,6 +29,11 @@ namespace Elastic.SemanticKernel.Connectors.Elasticsearch;
2729
/// </summary>
2830
internal class MockableElasticsearchClient
2931
{
32+
private static readonly RequestConfiguration CustomUserAgentRequestConfiguration = new RequestConfiguration
33+
{
34+
UserAgent = UserAgent.Create("elasticsearch-net", typeof(IElasticsearchClientSettings), ["integration=MSSK"])
35+
};
36+
3037
/// <summary>
3138
/// Initializes a new instance of the <see cref="MockableElasticsearchClient" /> class.
3239
/// </summary>
@@ -38,18 +45,7 @@ public MockableElasticsearchClient(ElasticsearchClient elasticsearchClient)
3845
{
3946
Verify.NotNull(elasticsearchClient);
4047

41-
// Create a private instance of the ElasticsearchClient based on the settings of the original instance.
42-
43-
if (elasticsearchClient.ElasticsearchClientSettings is not ElasticsearchClientSettings settings)
44-
{
45-
throw new NotSupportedException("Unsupported Elasticsearch client instance.");
46-
}
47-
48-
// TODO: Clone Settings
49-
50-
settings.UserAgent(UserAgent.Create($"{elasticsearchClient.ElasticsearchClientSettings.UserAgent}; integration=MSSK"));
51-
52-
ElasticsearchClient = new ElasticsearchClient(settings);
48+
ElasticsearchClient = elasticsearchClient;
5349
}
5450

5551
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
@@ -77,7 +73,12 @@ internal MockableElasticsearchClient()
7773
public virtual async Task<IReadOnlyList<string>> ListIndicesAsync(CancellationToken cancellationToken = default)
7874
{
7975
var response = await ElasticsearchClient.Indices
80-
.StatsAsync(cancellationToken)
76+
.StatsAsync(
77+
new IndicesStatsRequest
78+
{
79+
RequestConfiguration = CustomUserAgentRequestConfiguration
80+
},
81+
cancellationToken)
8182
.ConfigureAwait(false);
8283

8384
if (!response.IsSuccess())
@@ -102,7 +103,12 @@ public virtual async Task<bool> IndexExistsAsync(
102103
Verify.NotNull(indexName);
103104

104105
var response = await ElasticsearchClient.Indices
105-
.ExistsAsync(indexName, cancellationToken)
106+
.ExistsAsync(
107+
new ExistsRequest(indexName)
108+
{
109+
RequestConfiguration = CustomUserAgentRequestConfiguration
110+
},
111+
cancellationToken)
106112
.ConfigureAwait(false);
107113

108114
if (!response.IsSuccess())
@@ -129,13 +135,15 @@ public virtual async Task CreateIndexAsync(
129135
Verify.NotNull(indexName);
130136

131137
var response = await ElasticsearchClient.Indices
132-
.CreateAsync(new CreateIndexRequest(indexName)
133-
{
134-
Mappings = new TypeMapping
138+
.CreateAsync(
139+
new CreateIndexRequest(indexName)
135140
{
136-
Properties = properties
137-
}
138-
},
141+
Mappings = new TypeMapping
142+
{
143+
Properties = properties
144+
},
145+
RequestConfiguration = CustomUserAgentRequestConfiguration
146+
},
139147
cancellationToken)
140148
.ConfigureAwait(false);
141149

@@ -158,7 +166,12 @@ public virtual async Task DeleteIndexAsync(
158166
{
159167
Verify.NotNull(indexName);
160168

161-
var response = await ElasticsearchClient.Indices.DeleteAsync(indexName, cancellationToken)
169+
var response = await ElasticsearchClient.Indices.DeleteAsync(
170+
new DeleteIndexRequest(indexName)
171+
{
172+
RequestConfiguration = CustomUserAgentRequestConfiguration
173+
},
174+
cancellationToken)
162175
.ConfigureAwait(false);
163176

164177
if (!response.IsSuccess())
@@ -176,7 +189,12 @@ public virtual async Task DeleteIndexAsync(
176189
Verify.NotNull(id);
177190

178191
var response = await ElasticsearchClient
179-
.GetAsync<JsonObject>(indexName, id, x => { }, cancellationToken)
192+
.GetAsync<JsonObject>(
193+
new GetRequest(indexName, id)
194+
{
195+
RequestConfiguration = CustomUserAgentRequestConfiguration
196+
},
197+
cancellationToken)
180198
.ConfigureAwait(false);
181199

182200
if (!response.IsSuccess())
@@ -212,7 +230,12 @@ public virtual async Task<string> IndexDocumentAsync<TDocument>(
212230
Verify.NotNull(document);
213231

214232
var response = await ElasticsearchClient
215-
.IndexAsync(document, indexName, id, cancellationToken)
233+
.IndexAsync(
234+
new IndexRequest<TDocument>(document, indexName, id)
235+
{
236+
RequestConfiguration = CustomUserAgentRequestConfiguration
237+
},
238+
cancellationToken)
216239
.ConfigureAwait(false);
217240

218241
if (!response.IsSuccess())
@@ -240,7 +263,12 @@ public virtual async Task DeleteDocumentAsync(
240263
Verify.NotNull(id);
241264

242265
var response = await ElasticsearchClient
243-
.DeleteAsync(indexName, id, cancellationToken)
266+
.DeleteAsync(
267+
new DeleteRequest(indexName, id)
268+
{
269+
RequestConfiguration = CustomUserAgentRequestConfiguration
270+
},
271+
cancellationToken)
244272
.ConfigureAwait(false);
245273

246274
if (!response.IsSuccess())
@@ -270,11 +298,16 @@ public virtual async Task DeleteDocumentAsync(
270298
Verify.NotNull(query);
271299

272300
var response = await ElasticsearchClient
273-
.SearchAsync<JsonObject>(indexName, x => x
274-
.Query(query)
275-
.From(from)
276-
.Size(size),
277-
cancellationToken)
301+
.SearchAsync<JsonObject>(
302+
new SearchRequest(indexName)
303+
{
304+
Query = query,
305+
From = from,
306+
Size = size,
307+
RequestConfiguration = CustomUserAgentRequestConfiguration
308+
},
309+
cancellationToken
310+
)
278311
.ConfigureAwait(false);
279312

280313
if (!response.IsSuccess())

‎Elastic.SemanticKernel.Connectors.Elasticsearch/packages.lock.json

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
".NETStandard,Version=v2.0": {
55
"Elastic.Clients.Elasticsearch": {
66
"type": "Direct",
7-
"requested": "[8.15.10, )",
8-
"resolved": "8.15.10",
9-
"contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==",
7+
"requested": "[8.16.1, )",
8+
"resolved": "8.16.1",
9+
"contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==",
1010
"dependencies": {
11-
"Elastic.Transport": "0.4.26"
11+
"Elastic.Transport": "0.5.5"
1212
}
1313
},
14+
"Microsoft.Build.CopyOnWrite": {
15+
"type": "Direct",
16+
"requested": "[1.0.334, )",
17+
"resolved": "1.0.334",
18+
"contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ=="
19+
},
1420
"Microsoft.SemanticKernel.Abstractions": {
1521
"type": "Direct",
16-
"requested": "[1.26.0, )",
17-
"resolved": "1.26.0",
18-
"contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==",
22+
"requested": "[1.29.0, )",
23+
"resolved": "1.29.0",
24+
"contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==",
1925
"dependencies": {
2026
"Microsoft.Bcl.AsyncInterfaces": "8.0.0",
2127
"Microsoft.Bcl.HashCode": "1.1.1",
@@ -68,11 +74,12 @@
6874
},
6975
"Elastic.Transport": {
7076
"type": "Transitive",
71-
"resolved": "0.4.26",
72-
"contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ==",
77+
"resolved": "0.5.5",
78+
"contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q==",
7379
"dependencies": {
7480
"Microsoft.CSharp": "4.7.0",
7581
"System.Buffers": "4.5.1",
82+
"System.Collections.Immutable": "8.0.0",
7683
"System.Diagnostics.DiagnosticSource": "8.0.0",
7784
"System.Text.Json": "8.0.5",
7885
"System.Threading.Tasks.Extensions": "4.5.4"
@@ -152,6 +159,15 @@
152159
"resolved": "4.5.1",
153160
"contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg=="
154161
},
162+
"System.Collections.Immutable": {
163+
"type": "Transitive",
164+
"resolved": "8.0.0",
165+
"contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==",
166+
"dependencies": {
167+
"System.Memory": "4.5.5",
168+
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
169+
}
170+
},
155171
"System.Diagnostics.DiagnosticSource": {
156172
"type": "Transitive",
157173
"resolved": "8.0.1",
@@ -203,18 +219,24 @@
203219
"net8.0": {
204220
"Elastic.Clients.Elasticsearch": {
205221
"type": "Direct",
206-
"requested": "[8.15.10, )",
207-
"resolved": "8.15.10",
208-
"contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==",
222+
"requested": "[8.16.1, )",
223+
"resolved": "8.16.1",
224+
"contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==",
209225
"dependencies": {
210-
"Elastic.Transport": "0.4.26"
226+
"Elastic.Transport": "0.5.5"
211227
}
212228
},
229+
"Microsoft.Build.CopyOnWrite": {
230+
"type": "Direct",
231+
"requested": "[1.0.334, )",
232+
"resolved": "1.0.334",
233+
"contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ=="
234+
},
213235
"Microsoft.SemanticKernel.Abstractions": {
214236
"type": "Direct",
215-
"requested": "[1.26.0, )",
216-
"resolved": "1.26.0",
217-
"contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==",
237+
"requested": "[1.29.0, )",
238+
"resolved": "1.29.0",
239+
"contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==",
218240
"dependencies": {
219241
"Microsoft.Bcl.AsyncInterfaces": "8.0.0",
220242
"Microsoft.Bcl.HashCode": "1.1.1",
@@ -250,8 +272,8 @@
250272
},
251273
"Elastic.Transport": {
252274
"type": "Transitive",
253-
"resolved": "0.4.26",
254-
"contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ=="
275+
"resolved": "0.5.5",
276+
"contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q=="
255277
},
256278
"Microsoft.Bcl.AsyncInterfaces": {
257279
"type": "Transitive",

‎Elastic.SemanticKernel.Playground/packages.lock.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
"net8.0": {
55
"Elastic.Clients.Elasticsearch": {
66
"type": "Direct",
7-
"requested": "[8.15.10, )",
8-
"resolved": "8.15.10",
9-
"contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==",
7+
"requested": "[8.16.1, )",
8+
"resolved": "8.16.1",
9+
"contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==",
1010
"dependencies": {
11-
"Elastic.Transport": "0.4.26"
11+
"Elastic.Transport": "0.5.5"
1212
}
1313
},
14+
"Microsoft.Build.CopyOnWrite": {
15+
"type": "Direct",
16+
"requested": "[1.0.334, )",
17+
"resolved": "1.0.334",
18+
"contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ=="
19+
},
1420
"Elastic.Transport": {
1521
"type": "Transitive",
16-
"resolved": "0.4.26",
17-
"contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ=="
22+
"resolved": "0.5.5",
23+
"contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q=="
1824
},
1925
"Microsoft.Bcl.AsyncInterfaces": {
2026
"type": "Transitive",
@@ -57,17 +63,17 @@
5763
"elastic.semantickernel.connectors.elasticsearch": {
5864
"type": "Project",
5965
"dependencies": {
60-
"Elastic.Clients.Elasticsearch": "[8.15.10, )",
61-
"Microsoft.SemanticKernel.Abstractions": "[1.26.0, )",
66+
"Elastic.Clients.Elasticsearch": "[8.16.1, )",
67+
"Microsoft.SemanticKernel.Abstractions": "[1.29.0, )",
6268
"MinVer": "[6.0.0, )",
6369
"System.Text.Json": "[8.0.5, )"
6470
}
6571
},
6672
"Microsoft.SemanticKernel.Abstractions": {
6773
"type": "CentralTransitive",
68-
"requested": "[1.26.0, )",
69-
"resolved": "1.26.0",
70-
"contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==",
74+
"requested": "[1.29.0, )",
75+
"resolved": "1.29.0",
76+
"contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==",
7177
"dependencies": {
7278
"Microsoft.Bcl.AsyncInterfaces": "8.0.0",
7379
"Microsoft.Bcl.HashCode": "1.1.1",

0 commit comments

Comments
 (0)
Please sign in to comment.