elasticsearch-net icon indicating copy to clipboard operation
elasticsearch-net copied to clipboard

Completion type property does not like Contexts described with the fluent/lambda API when nested

Open TheFireCookie opened this issue 1 year ago • 4 comments

Elastic.Clients.Elasticsearch version: 8.9.1

Elasticsearch version: 8.9.0

.NET runtime version: 7.0.9

Operating system version: Windows 11

Description of the problem including expected versus actual behavior: Describing a completion property with some contexts with the fluent api descriptor like this

        .Properties(f => f
          .Completion(completionField, cp => cp
            .Analyzer(Es.Analyzer.ViaSuggest)
            .Contexts(
              c => c
                .Type(Es.Completion.Context.Type)
                .Name(Es.Completion.Context.Fqn)
            )
          )

generate this concrete mapping which is missing the contexts

                "suggests": {
                    "analyzer": "viaSuggestAnalyzer",
                    "max_input_length": 50,
                    "preserve_position_increments": true,
                    "preserve_separators": true,
                    "type": "completion"
                }

But if I describe the contexts in C# like this with a List:

        .Properties(f => f
          .Completion(completionField, cp => cp
            .Analyzer(Es.Analyzer.ViaSuggest)
            .Contexts( new List<SuggestContext> { new() { Name = Es.Completion.Context.Fqn, Type = Es.Completion.Context.Type } } )
          )

then the correct JSON is generated:

                "suggests": {
                    "analyzer": "viaSuggestAnalyzer",
                    "contexts": [{
                            "name": "fqn",
                            "type": "CATEGORY"
                        }
                    ],
                    "max_input_length": 50,
                    "preserve_position_increments": true,
                    "preserve_separators": true,
                    "type": "completion"
                }

TheFireCookie avatar Aug 03 '23 12:08 TheFireCookie

The descriptor looks fine and a minimalistic test provides the correct results:

var client = new ElasticsearchClient();

var desc = new CompletionPropertyDescriptor()
	.Analyzer("viaSuggestAnalyzer")
	.Contexts(x => x
		.Type("typ")
		.Name("test"));

var ms = new MemoryStream();
client.RequestResponseSerializer.Serialize(desc, ms, SerializationFormatting.Indented);
ms.Position = 0;
var sr = new StreamReader(ms);
var s = sr.ReadToEnd();
Console.WriteLine(s);
{
  "contexts": [
    {
      "name": "test",
      "type": "typ"
    }
  ],
  "analyzer": "viaSuggestAnalyzer",
  "type": "completion"
}

I will check this again in a bigger context.

flobernd avatar Aug 03 '23 13:08 flobernd

Indeed I'm in a much deeper context (sub-property in a full index mapping)

TheFireCookie avatar Aug 03 '23 14:08 TheFireCookie

Had the same issue here, my schema is pretty flat, no nested object. had to use the list way, the fluent api way doesnt work at all.

icyice80 avatar Jan 30 '24 01:01 icyice80

I was able to reproduce the issue now, but it requires a rather complex change in the code generator. Leaving this open until I have time to work on it 🙂

flobernd avatar Apr 18 '24 10:04 flobernd