Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7167185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:32:13+00:00 2026-05-28T14:32:13+00:00

I am trying to add about 21,000 entities already in the database into an

  • 0

I am trying to add about 21,000 entities already in the database into an nhibernate-search Lucene index. When done, the indexes are around 12 megabytes. I think the time can vary quite a bit, but it’s always very slow. In my last run (running with the debugger), it took over 12 minutes to index the data.

private void IndexProducts(ISessionFactory sessionFactory)
{
  using (var hibernateSession = sessionFactory.GetCurrentSession())
  using (var luceneSession = Search.CreateFullTextSession(hibernateSession))
  {
    var tx = luceneSession.BeginTransaction();
    foreach (var prod in hibernateSession.Query<Product>())
    {
      luceneSession.Index(prod);
      hibernateSession.Evict(prod);
    }
    hibernateSession.Clear();
    tx.Commit();
  }
}

The vast majority of the time is spent in tx.Commit(). From what I’ve read of Hibernate search, this is to be expected. I’ve come across quite a few ways to help, such as MassIndexer, flushToIndexes, batch modes, etc. But as far as I can tell these are Java-only options.

The session clear and evict are just desperate moves by me – I haven’t seen them make a difference one way or another.

Has anyone had success quickly indexing a large amount of existing data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:32:14+00:00Added an answer on May 28, 2026 at 2:32 pm

    I’ve been able to speed up considerable indexing by using a combination of batching and transactions.

    My initial code took ~30 minutes to index ~20.000 entities. Using the code bellow I’ve got it down to ~4 minutes.

        private void IndexEntities<TEntity>(IFullTextSession session) where TEntity : class
        {
            var currentIndex = 0;
            const int batchSize = 500;
    
            while (true)
            {
                var entities = session
                    .CreateCriteria<TEntity>()
                    .SetFirstResult(currentIndex)
                    .SetMaxResults(batchSize)
                    .List();
    
                using (var tx = session.BeginTransaction())
                {
                    foreach (var entity in entities)
                    {
                        session.Index(entity);
                    }
                    currentIndex += batchSize;
    
                    session.Flush();
                    tx.Commit();
                    session.Clear();
                }
    
                if (entities.Count < batchSize)
                    break;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about some functionality I'm trying to add to my jQuery
Trying to add a class object into a List using reflection, but when invoking
I have a project of about 7000 files, of which I'm trying to add
I'm trying to import some XML data into my MySQL database after processing it
I'm trying to add the output of git describe to the about window of
I'm trying to secure a older classic asp web site (that has about 1,000
I'm trying to import all googlebooks-1gram files into a postgresql database. I wrote the
Here's my problem: I'm trying to parse a big text file (about 15,000 KB) and
I am trying to add AppWidget into my application, but it seems like android
I have been playing about with a GUI today and trying add different elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.