I am trying to query the CompletionSuggester using Elastic.Clients.Elasticsearch. I am able to query with the following (use either prefix OR regex gets the right result):
POST customer-catalog-test-0001/_search
{
"_source": false,
"suggest": {
"product-suggest": {
"prefix": "male",
"regex": ".*male.*",
"completion": {
"field": "autoCompleteSuggest",
"skip_duplicates": true,
"size": 5
}
}
}
}
BUT when I am converting it to DotNet Elastic.Clients.Elasticsearch (v8.17), in the CompletionSuggester class, there is not Prefix
field, only Regex
field that takes Elastic.Clients.Elasticsearch.Core.Search.RegexOptions
. However, I cannot set the "expression" for the RegexOptions
. This is what the RegexOptions
like:
public sealed partial class RegexOptions
{
/// <summary>
/// <para>
/// Optional operators for the regular expression.
/// </para>
/// </summary>
[JsonInclude, JsonPropertyName("flags")]
public object? Flags { get; set; }
/// <summary>
/// <para>
/// Maximum number of automaton states required for the query.
/// </para>
/// </summary>
[JsonInclude, JsonPropertyName("max_determinized_states")]
public int? MaxDeterminizedStates { get; set; }
}
My current code:
public async void QuerySuggest()
{
var client = new ElasticsearchClient(new ElasticsearchClientSettings(new Uri("http://localhost:9200")));
var searchRequest = new SearchRequest("customer-catalog-test-0001")
{
// Exclude the _source
Source = new SourceConfig(false),
// Define the suggester
Suggest = new Suggester
{
Suggesters =
{
{
"product-suggest",
new CompletionSuggester
{
Field = "autoCompleteSuggest",
Size = 5,
SkipDuplicates = true,
Regex = new RegexOptions
{
Value = "male.*"
}
}
}
}
}
};
}
So..., am I not doing it right OR there is something wrong with CompletionSuggester/RegexOptions defination?