System.OutOfMemoryException - Nest Elasticsearch

Off Late I've been facing the below issue a lot(sometimes even while indexing a large document it has this problem). Can some one tell me what can be the reason behind this?

I just tried to run a simple search application which will return a 5 documents sorted in descending order of indexed date.

var response = client.Search<Document>(s => s
                                   .Size(5)
                                   .Sort(so => so
                                   .Descending(d => d
                                   .IndexedDate)));

The same code works perfectly fine when I run on the local host. Dont know whats wrong if I run the application on the server.

FailureReason: Unexpected when trying to POST http://192.168.x.y:9200/codetweaks54/document/_search

  • BadResponse: Node: http://192.168.x.y:9200/ Exception: OutOfMemoryException Took: 00:00:20.3557156
    Audit exception in step 0 BadResponse:
    System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
    at Newtonsoft.Json.Utilities.BufferUtils.RentBuffer(IArrayPool 1 bufferPool, Int32 minSize)
    at Newtonsoft.Json.JsonTextReader.ReadData(Boolean append, Int32 charsRequired)
    at Newtonsoft.Json.JsonTextReader.ReadData(Boolean append)
    at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
    at Newtonsoft.Json.JsonTextReader.ParseString(Char quote, ReadType readType)
    at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
    at Newtonsoft.Json.JsonTextReader.ReadAsString()
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
    at Newtonsoft.Json.Serialization.JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target)
    at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader, Object target)
    at Nest.ConcreteTypeConverter`

Again. This is not related to elasticsearch code IMO.

You should move your question to #development channel I think.

Unless you see in elasticsearch nodes a trace?

Yeah. I remember posting a similar question which as you said is not problem with ES after looking at my code. But this time its giving a problem only at few instances. like local server is perfectly fine while running it on a different server is throwing this. Thats why posted this question again.
Anyways will move it to development.

Thanks David.