Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
maximpashuk opened this issue Oct 30, 2013 · 2 comments

Comments

@maximpashuk
Copy link

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.

@Mpdreamz
Copy link
Member

Good catch, this seems like a better default behaviour if you go the all typed route.

@maximpashuk
Copy link
Author

Will you include my suggestion in 0.11.6 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants