# Slow Indexing

**URL:** <https://discuss.elastic.co/t/slow-indexing/10634>\
**Category:** Elasticsearch\
**Created:** [February 6, 2013, 11:47am UTC](https://discuss.elastic.co/t/slow-indexing/10634 "2013-02-06T11:47:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ophir\_Michaeli](https://avatars.discourse-cdn.com/v4/letter/o/9f8e36/32.png) [@Ophir\_Michaeli](https://discuss.elastic.co/u/Ophir_Michaeli)\
**Post date:** [February 6, 2013, 11:47am UTC](https://discuss.elastic.co/t/slow-indexing/10634/1 "2013-02-06T11:47:07Z")

</div>

Hi,

Testing a possible move from lucene to elasticsearch I created  
elasticsearch code with NEST client that imitates the lucene indexing I'm  
doing in my code.

The results were that the elasticsearch indexing took 10 times longer the  
direct lucene indexing of the same data.

This is the NEST code I use:

Call once from the constructor –

private void CreateEsIndex()

```
    {

        MapAndAnalyze(

            a => a.Analyzers(an => an.Add(snowball, new SnowballAnalyzer{ Language = language })),

            m => m

                     .Properties(p => p

                                          .String(sm => sm

                                                            .Name(f => 

```

f.Description)

.IndexAnalyzer(snowball)

.SearchAnalyzer(snowball)

```
                                                            .Store(false

```

)

```
                                          )

                                          .String(sm => sm.Name(f => 

```

f.Board).Store(false))

```
                                          .String(sm => sm.Name(f => 

```

f.User).Store(false))

```
                                          .String(sm => sm.Name(f => 

```

f.IDPin).Store())

```
                                          .String(sm => sm.Name(f => 

```

f.IDPicture).Store())

```
                     )

                     .DisableAllField()

            );

    }

    private void MapAndAnalyze(

        Func<AnalysisDescriptor, AnalysisDescriptor> analysisSelector,

        Func<RootObjectMappingDescriptor<Document>, 

```

RootObjectMappingDescriptor\> typeMappingDescriptor

```
        )

    {

        if (!client.IndexExists(index).Exists)

        {

            var result = client.CreateIndex(

                index, c => c

                                .NumberOfReplicas(0)

                                .NumberOfShards(5)

                                .Analysis(analysisSelector)

                                .AddMapping(typeMappingDescriptor)

                );

            Log.InfoFormat("Index Created: {0}", result.OK);

        }

    }

```

Call for each indexing –

var indexResult = client.Index(

```
                        new Document(

                            pin.Id.ToString(), 

```

pin.InnerData.PictureID.ToString(), pin.InnerData.Board, pin.InnerData.User,

```
                            pin.InnerData.Description.ToString(), id), 

```

index,

```
                        new IndexParameters { Refresh = true });

```

Thanks,

Ophir

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 6, 2013, 12:27pm UTC](https://discuss.elastic.co/t/slow-indexing/10634/2 "2013-02-06T12:27:22Z")

</div>

Could you try with Bulk instead of single insertion?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 févr. 2013 à 12:47, Ophir Michaeli [ophirmichaeli@gmail.com](mailto:ophirmichaeli@gmail.com) a écrit :

Hi,

Testing a possible move from lucene to elasticsearch I created elasticsearch code with NEST client that imitates the lucene indexing I'm doing in my code.

The results were that the elasticsearch indexing took 10 times longer the direct lucene indexing of the same data.

This is the NEST code I use:

Call once from the constructor –

private void CreateEsIndex()

```
    {

        MapAndAnalyze(

            a => a.Analyzers(an => an.Add(snowball, new SnowballAnalyzer { Language = language })),

            m => m

                     .Properties(p => p

                                          .String(sm => sm

                                                            .Name(f => f.Description)

                                                            .IndexAnalyzer(snowball)

                                                            .SearchAnalyzer(snowball)

                                                            .Store(false)

                                          )

                                          .String(sm => sm.Name(f => f.Board).Store(false))

                                          .String(sm => sm.Name(f => f.User).Store(false))

                                          .String(sm => sm.Name(f => f.IDPin).Store())

                                          .String(sm => sm.Name(f => f.IDPicture).Store())

                     )

                     .DisableAllField()

            );

    }

    private void MapAndAnalyze(

        Func<AnalysisDescriptor, AnalysisDescriptor> analysisSelector,

        Func<RootObjectMappingDescriptor<Document>, RootObjectMappingDescriptor<Document>> typeMappingDescriptor

        )

    {

        if (!client.IndexExists(index).Exists)

        {

            var result = client.CreateIndex(

                index, c => c

                                .NumberOfReplicas(0)

                                .NumberOfShards(5)

                                .Analysis(analysisSelector)

                                .AddMapping(typeMappingDescriptor)

                );

            Log.InfoFormat("Index Created: {0}", result.OK);

        }

    }

```

Call for each indexing –

var indexResult = client.Index(

```
                        new Document(

                            pin.Id.ToString(), pin.InnerData.PictureID.ToString(), pin.InnerData.Board, pin.InnerData.User,

                            pin.InnerData.Description.ToString(), id), index,

                        new IndexParameters { Refresh = true });

```

Thanks,

Ophir

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [February 6, 2013, 1:38pm UTC](https://discuss.elastic.co/t/slow-indexing/10634/3 "2013-02-06T13:38:11Z")

</div>

I see that you perform a refresh with the index operation. Are you doing  
this for each request?  
Setting refresh=true for each index request is not recommended. By default  
ES will perform a refresh periodically (1 second). The automatic refresh is  
configurable.

Martijn

On 6 February 2013 13:27, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Could you try with Bulk instead of single insertion?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 févr. 2013 à 12:47, Ophir Michaeli [ophirmichaeli@gmail.com](mailto:ophirmichaeli@gmail.com) a  
> écrit :
> 
> Hi,
> 
> Testing a possible move from lucene to elasticsearch I created  
> elasticsearch code with NEST client that imitates the lucene indexing I'm  
> doing in my code.
> 
> The results were that the elasticsearch indexing took 10 times longer the  
> direct lucene indexing of the same data.
> 
> This is the NEST code I use:
> 
> Call once from the constructor –
> 
> private void CreateEsIndex()
> 
> ```
> {
> 
> MapAndAnalyze(
> 
> a => a.Analyzers(an => an.Add(snowball, new
> 
> ```
> 
> SnowballAnalyzer { Language = language })),
> 
> ```
> m => m
> 
> .Properties(p => p
> 
> .String(sm => sm
> 
> .Name(f
> 
> ```
> 
> =\> f.Description)
> 
> .IndexAnalyzer(snowball)
> 
> .SearchAnalyzer(snowball)
> 
> ```
> .Store(
> 
> ```
> 
> false)
> 
> ```
> )
> 
> .String(sm => sm.Name(f =>
> 
> ```
> 
> f.Board).Store(false))
> 
> ```
> .String(sm => sm.Name(f =>
> 
> ```
> 
> f.User).Store(false))
> 
> ```
> .String(sm => sm.Name(f =>
> 
> ```
> 
> f.IDPin).Store())
> 
> ```
> .String(sm => sm.Name(f =>
> 
> ```
> 
> f.IDPicture).Store())
> 
> ```
> )
> 
> .DisableAllField()
> 
> );
> 
> }
> 
> private void MapAndAnalyze(
> 
> Func<AnalysisDescriptor, AnalysisDescriptor> analysisSelector,
> 
> Func<RootObjectMappingDescriptor<Document>,
> 
> ```
> 
> RootObjectMappingDescriptor\> typeMappingDescriptor
> 
> ```
> )
> 
> {
> 
> if (!client.IndexExists(index).Exists)
> 
> {
> 
> var result = client.CreateIndex(
> 
> index, c => c
> 
> .NumberOfReplicas(0)
> 
> .NumberOfShards(5)
> 
> .Analysis(analysisSelector)
> 
> .AddMapping(typeMappingDescriptor)
> 
> );
> 
> Log.InfoFormat("Index Created: {0}", result.OK);
> 
> }
> 
> }
> 
> ```
> 
> Call for each indexing –
> 
> var indexResult = client.Index(
> 
> ```
> new Document(
> 
> pin.Id.ToString(),
> 
> ```
> 
> pin.InnerData.PictureID.ToString(), pin.InnerData.Board, pin.InnerData.User,
> 
> ```
> pin.InnerData.Description.ToString(),
> 
> ```
> 
> id), index,
> 
> ```
> new IndexParameters { Refresh = true });
> 
> ```
> 
> Thanks,
> 
> Ophir
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:52am UTC](https://discuss.elastic.co/t/slow-indexing/10634/4 "2017-07-06T02:52:46Z")

</div>


