Skip to content

Commit

Permalink
Correctly create custom analyzer in Elasticsearch (#17013)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Nov 14, 2024
1 parent 998ce27 commit 05bd65a
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ internal static ElasticsearchOptions AddAnalyzers(this ElasticsearchOptions opti
return options;
}

internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options, IConfigurationSection configuration)
internal static ElasticsearchOptions AddTokenFilters(this ElasticsearchOptions options, IConfigurationSection configuration)
{
var jsonNode = configuration.GetSection(nameof(options.Filter)).AsJsonNode();
var jsonNode = configuration.GetSection(nameof(options.TokenFilters)).AsJsonNode();
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonNode);

var filterObject = JsonObject.Create(jsonElement, new JsonNodeOptions()
Expand All @@ -66,7 +66,7 @@ internal static ElasticsearchOptions AddFilter(this ElasticsearchOptions options
continue;
}

options.Filter.Add(filter.Key, jFilter);
options.TokenFilters.Add(filter.Key, jFilter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public override void ConfigureServices(IServiceCollection services)
return new ElasticClient(options.GetConnectionSettings() ?? new ConnectionSettings());
});

services.Configure<ElasticsearchOptions>(o =>
services.Configure<ElasticsearchOptions>(options =>
{
var configuration = _shellConfiguration.GetSection(ElasticConnectionOptionsConfigurations.ConfigSectionName);
o.AddIndexPrefix(configuration);
o.AddFilter(configuration);
o.AddAnalyzers(configuration);
options.AddIndexPrefix(configuration);
options.AddTokenFilters(configuration);
options.AddAnalyzers(configuration);
});

services.AddElasticServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class ElasticsearchOptions

public Dictionary<string, JsonObject> Analyzers { get; } = [];

public Dictionary<string, JsonObject> Filter { get; } = [];
public Dictionary<string, JsonObject> TokenFilters { get; } = [];
}
Loading

0 comments on commit 05bd65a

Please sign in to comment.