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

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

Open kylepmanuel opened this issue 1 year ago • 0 comments

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)
            )
        )

kylepmanuel avatar Apr 12 '24 14:04 kylepmanuel