Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix tsc read elasticsearch mapping #631

Merged
merged 3 commits into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@ await client.SearchAsync<TResult>(s => searchDescriptorFunc(s.Index(indexName)).

#region mapping

/// <summary>
/// 获取mapping
/// </summary>
/// <param name="caller"></param>
/// <param name="indexName"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<IEnumerable<MappingResponseDto>> GetMappingAsync(this ICaller caller, string indexName, CancellationToken token = default)
{
var path = $"/{indexName}/_mapping";
var result = await caller.GetAsync<object>(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<MappingResponseDto>? GetRepProperties(JsonElement node, string? parentName = default)
Expand Down