Skip to content

Ability to use only per-type DefaultIndices dictionary, without setting global DefaultIndex at all #372

Closed
@maximpashuk

Description

@maximpashuk

Hi.

I have metadata-like dictionary, which maps document type to its index name.
It maps greatly on DefaultIndeces property of ConnectionSettings class.
Since I always work with strongly-typed API, there is no need for me to set global DefaultIndex property at all.
I can always get index name from metadata dictionary

But If you take a look at
https://github.com/Mpdreamz/NEST/blob/master/src/Nest/Resolvers/IndexNameResolver.cs

You will see that GetIndexForType method always touches DefaultIndex property, and touching this propery throws an exception "No default index set on connection!" if I not set it.

If it is will not get any troubles, can this part of code be rewritten without touching DefaultIndex property if DefaultIndices already contains index name?

Something like this:

        public string GetIndexForType(Type type)
        {
            var defaultIndices = this._connectionSettings.DefaultIndices;
            if (defaultIndices != null && defaultIndices.ContainsKey(type) && !string.IsNullOrWhiteSpace(defaultIndices[type]))
            {
                return defaultIndices[type]
            }

            return this._connectionSettings.DefaultIndex;
        }

Sorry for issue instead of pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions