Skip to content

Null Object Ref Error when creating index #319

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

Closed
Jonesie opened this issue Jul 24, 2013 · 3 comments
Closed

Null Object Ref Error when creating index #319

Jonesie opened this issue Jul 24, 2013 · 3 comments

Comments

@Jonesie
Copy link

Jonesie commented Jul 24, 2013

Hi
Ive just updated my nuget of Nest to the latest version 0.11.1.0 from 0.9.20.6 and I now get a null object ref creating the index. My code is unchanged, but maybe it was never right. I've also updated Json.Net to v 5.0.6.2 and the call stack indicated that the JsonSerializer is where its failing.

The call stack is thus:

at Nest.Resolvers.Converters.IndexSettingsConverter.<>c__DisplayClass2.b__0(RootObjectMapping m) in c:\Work\NEST\src\Nest\Resolvers\Converters\IndexSettingsConverter.cs:line 113
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable1 source, Func2 keySelector)
at Nest.Resolvers.Converters.IndexSettingsConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) in c:\Work\NEST\src\Nest\Resolvers\Converters\IndexSettingsConverter.cs:line 112
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, Formatting formatting, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings)
at Nest.ElasticClient.Serialize(Object object) in c:\Work\NEST\src\Nest\ElasticClient-Statics.cs:line 53
at Nest.ElasticClient.CreateIndex(String index, IndexSettings settings) in c:\Work\NEST\src\Nest\ElasticClient-CreateIndex.cs:line 18
...

My Code to create the index is below:

     var settings = new IndexSettings();
            settings.Similarity = new SimilaritySettings();
            settings.NumberOfReplicas = _configuration.Replicas;
            settings.NumberOfShards = _configuration.Shards;
            settings.Add("index.refresh_interval", "10s");
            settings.Add("merge.policy.merge_factor", "10");
            settings.Add("search.slowlog.threshold.fetch.warn", "1s");
            settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("keyword", new KeywordAnalyzer()));
            settings.Analysis.Analyzers.Add(new KeyValuePair<string, AnalyzerBase>("simple", new SimpleAnalyzer()));

     var idxRsp = client.CreateIndex(_settings.SearchIndexName, settings);
@Jonesie
Copy link
Author

Jonesie commented Jul 24, 2013

Looking at this a little closer it appears to be something to do with the field mappings. The TypeNameMarket is null.
I'm creating mappings by reading a definition in XML (not directly from Poco's), eg: new StringMapping() { Name = fieldname, Index = idx, Store = field.Store };

The help/docs say to use TypeMappingProperty but this is marked as obsolete.

@Mpdreamz
Copy link
Member

Hey Jonesie,

I think I am missing part of the puzzle, can you check the attached commit's unit test ?

@Mpdreamz
Copy link
Member

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