Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity framework transfer thousands of objects to Elastic Search
    primarykey
    data
    text
    <p>I am creating a web app that will have a database on every town, region and country in the world to allow for mapping other objects to a location. As part of the application I want the users to be able to search for a place, to do this I am using Elastic Search to index everything. To interact with Elastic Search I am using NEST.</p> <p>I have the following code:</p> <pre><code>public void RefreshLocationIndex() { int count; using (var dbContext = new ModelContext()) { IndexMany(dbContext.Countries, "Country"); } using (var dbContext = new ModelContext()) { count = dbContext.Regions.AsNoTracking().Count(); } for (var i = 0; i &lt;= count; i += BATCH_SIZE) { using (var innerContext = new ModelContext()) { IndexMany(innerContext.Regions.OrderBy(t =&gt; t.RegionID).Skip(i).Take(BATCH_SIZE), "Region"); } } using (var dbContext = new ModelContext()) { count = dbContext.Towns.AsNoTracking().Count(); } for (var i = 0; i &lt;= count; i += BATCH_SIZE) { using (var innerContext = new ModelContext()) { IndexMany(innerContext.Towns.AsNoTracking().OrderBy(t =&gt; t.TownID).Skip(i).Take(BATCH_SIZE), "Town"); } } } public void IndexMany(IQueryable&lt;Entity&gt; objects, string type) { var itemCount = objects.Count(); if (itemCount &gt; 0) { SearchClient.Instance.IndexManyAsync(objects, SearchClient.Instance.Settings.DefaultIndex, type); } } </code></pre> <p>As you can see I am separating the very large tables into batches to try to avoid loading to much into memory. The problem is this is not working, and I keep getting out of memory exceptions. I thought that using a new context for each batch would avoid this issue as when the context was disposed it would dispose of all the entities it had loaded, this doesn't seem to be the case. Any ideas?</p> <p>Just as an indication of the amount of data: Country table has 193 records Region table has 80,523 records Town table has 2,743,469 records</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload