Skip to content

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

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

Closed
TheFireCookie opened this issue Aug 3, 2023 · 4 comments · Fixed by #8485
Labels
8.x Relates to a 8.x client version Area: Generator Category: Bug

Comments

@TheFireCookie
Copy link
Contributor

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 TheFireCookie added the 8.x Relates to a 8.x client version label Aug 3, 2023
@flobernd
Copy link
Member

flobernd commented Aug 3, 2023

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.

@TheFireCookie
Copy link
Contributor Author

TheFireCookie commented Aug 3, 2023

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

@icyice80
Copy link

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.

@TheFireCookie TheFireCookie changed the title Completion type property does not like Contexts described with the fluent/lambda API Completion type property does not like Contexts described with the fluent/lambda API when nested Jan 30, 2024
@flobernd
Copy link
Member

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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version Area: Generator Category: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants