Skip to content

TokenFilters configured on IndexSettings are serialized incorrectly #7118

Closed
@stevejgordon

Description

@stevejgordon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions