elastic / elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html
Apache License 2.0
11 stars 1.15k forks source link

8.15.6 - Bring Back IProperty.Name #8336

Open niemyjski opened 2 months ago

niemyjski commented 2 months ago

Elastic.Clients.Elasticsearch version: 8.15.6

Elasticsearch version: 8.15.1

.NET runtime version: 8.x

Operating system version: Any

Description of the problem including expected versus actual behavior:

Seems really important for debugging and lookup purposes to have the field name attached to a property. Maybe this could be stored in local metadata?. We use this heavily in Foundatio.Parsers for:

  1. Getting server and local code mappings to resolve field names based on partial name matches.
  2. Help with resolving FieldAliasProperty (seems really odd that FieldAliasProperty is missing the name).

Expected behavior

Being able to lookup properties by name

Reference: https://github.com/FoundatioFx/Foundatio.Parsers/pull/84

flobernd commented 2 months ago

Hi @niemyjski,

this is a difficult one. In ES, property objects do not hold their names. They are always used as part of a dictionary (Properties type in the new client):

{
  "prop": {
    "my_property": {
      "type": "boolean",
      "...": "..."
    }
  }
}

Keeping the property name as local metadata in the IProperty instance could easily cause inconsistencies if the same IProperty instance is added to multiple Properties dictionaries while using different names for the keys.

Would it help, if I add an additional method to the Properties dictionary type that allows to perform a reverse lookup? Something like:

class Properties
{
    public string? TryGetName(IProperty property) { ... }
}
niemyjski commented 2 months ago

That would be extremely useful!