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