Skip to content

In the fluent index mapping using the Keyword property descriptor lambda method for a list of strings throws an exception #8121

Open
@kylepmanuel

Description

@kylepmanuel

Elastic.Clients.Elasticsearch version: 8.13.5

Elasticsearch version: 8.13.0

.NET runtime version: net6.0

Operating system version: win11

Description of the problem including expected versus actual behavior:
Using the fluent index mapping, the Keyword method signature that accepts a lambda (Expression<Func<TDocument, object>>) will throw an error on a list of strings.

Error:

Elastic.Transport.UnexpectedTransportException: 'Sequence contains no elements'

Steps to reproduce:
Using this test class:

    public class TestDoc
    {
       public IList<string> Tags { get; set; } = new List<string>();
    }

Attempt to create an index:

    var r = await Client.Indices.CreateAsync<TestDoc>("testdoc", c => c
      .Mappings(m => m
        .Properties(p => p
            .Text(t => t.Tags, c => c
              .Fields(f => f
                .Keyword(kk => kk, cc => cc
                  .IgnoreAbove(256)
                )
              )
            )
          )
        )
    );

Expected behavior
Should produce this mapping without error:

    "tags": {
      "type": "text",
      "fields": {
        "keyword": {
          "ignore_above": 256,
          "type": "keyword"
        }
      }
    }

Original question asked in the Elastic forum: Creating index for list of strings

Workaround:

    .Fields(f => f
            .Keyword("keyword", cc => cc
                .IgnoreAbove(256)
            )
        )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions