Closed
Description
Is your feature request related to a problem? Please describe.
The new list syntax leaves a lot ot be desired and a bit of a pain to upgrade to.
Describe the solution you'd like
.DynamicTemplates(t => t.DynamicTemplate("idx_text", t1 => t1.Match("text*").Mapping(m1 => m1.Text(mp => mp.AddKeywordAndSortFields()))))
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Activity
flobernd commentedon Mar 7, 2025
Hi @niemyjski ,
I guess this is about this construct:
Specification
I recently made some changes to the related specification (elastic/elasticsearch-specification#3824). This alone does not help here, but I have a strong feeling that the actual type should be
SingleKeyDictionary<string, DynamicTemplate>[]
which would map to:... which in theory is the same as a regular
Dictionary
, with the exception that this explicitly intends to preserve the order of items.Will do
My plan is to expose this property as just
IDictionary
and take care about the ordering at serialization layer (e.g. by usingOrderedDictionary<K,V>
).For descriptors, this would also be fully transparent to the user as you won't have to care about manually creating a dictionary.
The problem is with the regular object initializer syntax where the
IDictionary
could lead users to initialize the property using a regular dictionary (which might or might not preserve order of items; depending on the implementation). I have to think about this when I get to that point.If my above assumtion is correct and we can get away with just
IDictionary<string, DynamicTemplate>
, the descriptor usage would look similar to:Won't do
Other than that, the dictionary type will stay.
It's basically the same change that has been made for
Aggregation
where the name was previously pulled in to the object and now is external, in form of the dictionary key.For the object representation, this means that the
DynamicTemplate
type itself won't have a property holding its name.For the usages this means that we have to deal with
IDictionary<string, DynamicTemplate>
instead ofICollection<DynamicTemplate>
.niemyjski commentedon Mar 7, 2025
That sounds good, just curious why ordering matters?
flobernd commentedon Mar 7, 2025
@niemyjski I was surprised as well, but turns out Elasticsearch will always use the first matching template. That allows to add templates for very specific conditions first while still having more generic fallbacks later in the list.
And we already confirmed that my assumption was indeed correct and I can move forward with implementing this usability improvement 🙂