# Creating index for list of strings

**URL:** <https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 12, 2024, 6:09am UTC](https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258 "2024-04-12T06:09:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Manuel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kyle_manuel/32/123566_2.png) [@Kyle\_Manuel](https://discuss.elastic.co/u/Kyle_Manuel)\
**Post date:** [April 12, 2024, 6:09am UTC](https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258/1 "2024-04-12T06:09:45Z")

</div>

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:

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

```

I'm attempting with this test doc:

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

```

Mapping:

```auto
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.

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [April 12, 2024, 7:52am UTC](https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258/2 "2024-04-12T07:52:54Z")

</div>

Hi @Kyle_Manuel,

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

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [April 12, 2024, 8:05am UTC](https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258/3 "2024-04-12T08:05:39Z")

</div>

@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:

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

```

---

<div class="post-metadata">

**Author:** ![Kyle\_Manuel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kyle_manuel/32/123566_2.png) [@Kyle\_Manuel](https://discuss.elastic.co/u/Kyle_Manuel)\
**Post date:** [April 12, 2024, 2:05pm UTC](https://discuss.elastic.co/t/creating-index-for-list-of-strings/357258/4 "2024-04-12T14:05:56Z")

</div>

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