Skip to content

TokenFilters configured on IndexSettings are serialized incorrectly #7118

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
stevejgordon opened this issue Dec 15, 2022 · 0 comments · Fixed by #7120
Closed

TokenFilters configured on IndexSettings are serialized incorrectly #7118

stevejgordon opened this issue Dec 15, 2022 · 0 comments · Fixed by #7120
Labels
8.x Relates to a 8.x client version
Milestone

Comments

@stevejgordon
Copy link
Contributor

Generated code for open internally-tagged unions produces incorrect JSON when serialized. An example is when defining token filters on IndexSettings.

var createResponse = await client.Indices.CreateAsync("my-new-index", i => i
    .Settings(s => s
        .Analysis(a => a
            .Filter(f => f
                .Add("synonym", new TokenFilter(new TokenFilterDefinitions
                    {
                        { "synonym", new SynonymTokenFilter() { SynonymsPath = "analysis/synonym.txt" } }
                    })))
            .Analyzer(a => a
                .Custom("my-custom-analyzer", c => c
                    .Filter(new[] { "stop", "synonym" })
                    .Tokenizer("standard"))))));

The above produces:

{
    "settings": {
        "analysis": {
            "analyzer": {
                "my-custom-analyzer": {
                    "filter": ["stop", "synonym"],
                    "tokenizer": "standard",
                    "type": "custom"
                }
            },
            "filter": {
                "synonym": {
                    "synonym": {
                        "synonyms_path": "analysis/synonym.txt",
                        "type": "synonym"
                    }
                }
            }
        }
    }
}

We expect:

{
    "settings": {
        "analysis": {
            "analyzer": {
                "my-custom-analyzer": {
                    "filter": ["stop", "synonym"],
                    "tokenizer": "standard",
                    "type": "custom"
                }
            },
            "filter": {
                "synonym": {
                    "synonyms_path": "analysis/synonym.txt",
                    "type": "synonym"
                }
            }
        }
    }
}

This is due to the generation of TokenFilterDefinitions as IsADictionary required for this polymorphic type's open nature. This will affect other similarly specified types.

@stevejgordon stevejgordon added bug 8.x Relates to a 8.x client version labels Dec 15, 2022
@stevejgordon stevejgordon added this to the 8.0.3 milestone Dec 15, 2022
@stevejgordon stevejgordon modified the milestones: 8.0.3, 8.0.4 Dec 20, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant