Code Monkey home page Code Monkey logo

Comments (10)

Mpdreamz avatar Mpdreamz commented on May 27, 2024

The Index(IEnumerable) method doesn't partition for you so it will try to do a single call. Its best to partition yourself and index for every 1000 to 10,000 items going by how many data each items contains.

To speed up indexing i'd use the IndexAsync(IEnumerable) which returns a task you can wait on while it processes asynchronously in the background. There's a demo project that indexes a hacker news which might be helpful.

If that doesn't resolve your issue please paste the response you get from ElasticSearch (query ConnectionStatus.Response and ConnectionStatus.Request or use fiddler).

from elasticsearch-net.

 avatar commented on May 27, 2024

It didn't solve it, I even lowered my batches down to 2 in size. Batching code at the bottom as well.

response: {"error":"MapperParsingException[Malformed content, must start with an object]","status":400}
request: [{"divisions":[{"id":{"timestamp":1334773504,"machine":8097553,"pid":6552,"increment":8473475,"creationTime":"2012-04-18T18:25:04Z"}}],"type":1,"primaryDemo":{"id":533},"years":[2011],"name":"2Q'10 x.com week 3/28","harborTeamId":44,"advertiser":{"id":10643},"agency":{"id":31065},"agencyOffice":{"id":21035},"salesSplit":{"id":16537},"salesPlanner":{"id":3248},"spendingGoal":0.0,"cpmGoal":0.0,"id":{"timestamp":1338490981,"machine":14860174,"pid":4452,"increment":936677,"creationTime":"2012-05-31T19:03:01Z"},"brand":{"id":20862,"advertiserId":0},"calendar":0},{"divisions":[{"id":{"timestamp":1334773504,"machine":8097553,"pid":6552,"increment":8473471,"creationTime":"2012-04-18T18:25:04Z"}}],"type":0,"primaryDemo":{"id":36},"years":[2011,2012],"name":"11/12 Upfront","harborTeamId":3,"advertiser":{"id":2513},"agency":{"id":20660},"agencyOffice":{"id":10645},"salesSplit":{"id":21284},"salesPlanner":{"id":3700},"spendingGoal":0.0,"cpmGoal":0.0,"id":{"timestamp":1338490981,"machine":14860174,"pid":4452,"increment":960000,"creationTime":"2012-05-31T19:03:01Z"},"brand":{"id":1,"advertiserId":0},"calendar":0}]

ElasticClient.DeleteIndex();

var repo = Dependency.Container.Resolve<IRepository>();
var deals = repo.GetAll();
var batchSize = 2;

var current = 0;
var results = deals.Skip(0).Take(batchSize).ToList();
var tasks = new List<Task>();

while (results.Any() && current < 6)
{
var copy = results.ToArray();
tasks.Add(ElasticClient.IndexAsync(copy));
tasks.Last().ContinueWith(i => Console.WriteLine(i.Result.Result));
current += batchSize;
results = deals.Skip(current).Take(batchSize).ToList();
}

Task.WaitAll(tasks.ToArray());

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 27, 2024

Ahh i think i know whats going wrong here. C# infers the wrong generic method here.

Try explicit typing the index call tasks.Add(ElasticClient.IndexAsync<Division>(copy));

The copying itself should not be neccessary either.

Should i rename the IEnumerable overloaded index methods to IndexMany so c# will infer them better?

from elasticsearch-net.

 avatar commented on May 27, 2024

I think that makes sense, most people will not know to use the explicit version. That said, I'm now getting this exception with the change:

System.InvalidCastException occurred
  HResult=-2147467262
  Message=Object must implement IConvertible.
  Source=mscorlib
  StackTrace:
       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
       at Nest.ElasticClient.b__37[T](T object) in c:\Users\driggins\Documents\GitHub\NEST\src\Nest\ElasticClient-Inferno.cs:line 36
  InnerException: 

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 27, 2024

Try get the latest version from Nuget (or update your checkout).

It looks like its using an older version of ElasticClient-Inferno.cs
which is a couple commits behind.

For reference though, as i've never hit that error before, exactly what type is your Id property here ?

Thanks for your input! I'll update the calls to IndexMany.

from elasticsearch-net.

 avatar commented on May 27, 2024

It's a Mongo ObjectId type. I'll try updating now.

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 27, 2024

Ok in the update it should work with anything that implements a ToString() which makes sense to use as Id.

Curious if you have better luck now with Mongo's ObjectId here, let me know.

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 27, 2024

Just pushed 0.9.1.0 to nuget which contains the rename from Index(IEnumerable) to IndexMany(IEnumerable)

from elasticsearch-net.

 avatar commented on May 27, 2024

Works perfectly, also the new IndexMany worked great, was able to index everything without batching as well. Thanks for all the help!

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 27, 2024

Awesome, glad to know everything works a lot smoother now :)

from elasticsearch-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.