Creating index for list of strings

I'm using the Elastic.Clients.Elasticsearch NuGet package to migrate away from our existing Nest implementations. I am getting an error attempting to replicate the Nest mapping for a list of strings. If I remove the lambda containing the fields method call, it creates a normal text mapping fine. What am I doing wrong?

Nest's auto map created this mapping:

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

I'm attempting with this test doc:

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

Mapping:

var r = await Client.Indices.CreateAsync<TestDoc>($"{_indexPrefix}_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)
            )
          )
        )
      )
    )
);

I get this error:

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

The only details I can get from the exception are

Internal error in the expression evaluator.

Hi @Kyle_Manuel,

let me have a look, if this is a bug in the client :slightly_smiling_face:

@Kyle_Manuel I can confirm this exception which is caused by kk => kk. The field name inferrer expects a property here like kk => kk.Foo.

Could you please open an issue on GitHub? I have to do some research, because I'm not sure where NEST takes the keyword name from (not the type, but the key in the fields dictionary). Maybe the name does not matter at all?

As a workaround you could explicitly specify the field name instead of using the lambda:

.Mappings(m => m
    .Properties(p => p
        .Text(t => t.Tags, c => c
            .Fields(f => f
                .Keyword("keyword", cc => cc
                    .IgnoreAbove(256)
                )
            )
        )
    )
)

Thanks, I will open an issue for this. Your workaround worked for me.

1 Like