From e635a80454daddc78c5fd0e5b977a7e97d6d65ca Mon Sep 17 00:00:00 2001 From: Qinyouzeng <102203523+Qinyouzeng@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:39:37 +0800 Subject: [PATCH] fix: fix tsc read elasticsearch mapping (#631) * fix: fix tsc read elasticsearch mapping * chore: fix bug * fix: update --- .../Extenistions/IElasticClientExtenstion.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs index 96f334de0..9d5619586 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Tsc.Elasticsearch/Extenistions/IElasticClientExtenstion.cs @@ -34,24 +34,25 @@ await client.SearchAsync(s => searchDescriptorFunc(s.Index(indexName)). #region mapping - /// - /// 获取mapping - /// - /// - /// - /// - /// public static async Task> GetMappingAsync(this ICaller caller, string indexName, CancellationToken token = default) { var path = $"/{indexName}/_mapping"; var result = await caller.GetAsync(path, false, token); var json = (JsonElement)result!; - if (!json.TryGetProperty(indexName, out JsonElement root) || !root.TryGetProperty("mappings", out JsonElement mapping)) + JsonElement mapping = default; + bool findMapping = false; + foreach (var item in json.EnumerateObject()) { - return default!; + if (!findMapping && item.Value.TryGetProperty("mappings", out mapping)) + { + findMapping = true; + break; + } } - return GetRepProperties(mapping, default!)!; + if (findMapping) + return GetRepProperties(mapping, default!)!; + throw new UserFriendlyException($"can't find mapping for index: {indexName}"); } private static IEnumerable? GetRepProperties(JsonElement node, string? parentName = default)