# Elasticsearch- Single Index vs Multiple Indexes

**URL:** <https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265>\
**Category:** Elasticsearch\
**Created:** [January 15, 2019, 8:39am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265 "2019-01-15T08:39:33Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 16, 2019, 10:49am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/21 "2019-01-16T10:49:54Z")

</div>

Thanks @Mark_Harwood

> [@Mark\_Harwood](#):
>
> Benchmarking is your way forward here as there are so many variables to consider.

We will surely work on Benchmarking and update the results on the same thread.

Thank you again for your constant guidance.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 16, 2019, 12:23pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/22 "2019-01-16T12:23:36Z")

</div>

@Mark_Harwood

> [@pranav24](#):
>
> I would like to rephrase this question, When I divide a single index (which contains about 3000-4000 fields) into multiple indexes(which contains around 100 fields each), and search over all these indexes at once, the search would still be on about 3000-4000 fields is what I assume.

Considering the same quoted scenarios, I am not worried much about performance.  
I understand a mapping explosion is not a specific event but a general condition of having a lot of fields.

My main concern is if I have 30 indexes each with 100 fields, and then I search on all those 30 indexes using a single query. This will lead to searching on all 3000 fields (30 (Index) \* 100 (fields in each index)). Can there be a mapping explosion in this case?

The reason I am asking this question is each index in itself contains a low number of fields but the search query is spread across multiple indexes, which cumulates to a large number of fields being searched

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 16, 2019, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/23 "2019-01-16T12:40:39Z")

</div>

So you're asking "is 30 x 100 a lot"?

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 16, 2019, 1:15pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/24 "2019-01-16T13:15:00Z")

</div>

May be I did not put my question correctly at first time.  
The only confusion which I have is whether mapping explosion is restricted to search on a single index or is it true for search across cumulative fields of multiple indexes as well ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 16, 2019, 1:24pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/25 "2019-01-16T13:24:55Z")

</div>

They all add up

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 16, 2019, 3:09pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/26 "2019-01-16T15:09:40Z")

</div>

Thanks @Mark_Harwood for your continuous help  
I have read through this link [https://issues.apache.org/jira/browse/LUCENE-6842](https://issues.apache.org/jira/browse/LUCENE-6842) which talks about similar situation in Lucene.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 17, 2019, 7:58am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/27 "2019-01-17T07:58:51Z")

</div>

Thanks @Mark_Harwood for your continuous help. We are working on Benchmarking for our use cases.

I still have one question,  
If I am searching only for a single specified field on an index having 1000 fields, can mapping explosion occur ?

This situation is different from my previous use cases where I was searching on all fields. Now the search will only be on a specified field on index containing 1000 fields.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 17, 2019, 8:23am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/28 "2019-01-17T08:23:05Z")

</div>

Having a very large number of fields can as Mark points out lead to a lot of performance problems. If the number of fields however is static, it is in my opinion wrong to use the term mapping explosion. As outlined in [this rather old but still useful blog post](https://www.elastic.co/blog/found-crash-elasticsearch), mapping explosion is when the number of mapped fields continuously increases due to how the data model is structured. Each change requires the cluster state to be updated and propagated, and this typically gets slower the larger it gets, at some point causing severe performance and stability problems.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 22, 2019, 7:48am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/29 "2019-01-22T07:48:29Z")

</div>

Thanks for your response

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 22, 2019, 8:02am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/30 "2019-01-22T08:02:15Z")

</div>

@Mark_Harwood @Christian_Dahlqvist  
As per your suggestion, we have proceeded with benchmarking.  
Although we haven't faced any mapping explosion, our search has become drastically slow on a Free text search. Here is a summary.

```
Total Field Number : Time : Calls 
  2000 : 2-5s : Single call
  2000 : 2-15s : Multiple calls
  5000 : 15-40s : Single call
  5000 : 70-90s : Multiple calls  
  10000 : 25-35s : Single call
  10000 : 2-4 mins : Multiple calls

```

By Multiple calls, I mean 5 user searches simultaneously.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 22, 2019, 8:18am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/31 "2019-01-22T08:18:44Z")

</div>

More indexed fields = more data structures.  
More data structures = more random disk seeks.  
More random disk seeks = more time.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 22, 2019, 8:28am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/32 "2019-01-22T08:28:37Z")

</div>

As per our benchmarking results, we can conclude by saying, extensive number of fields will slow down my free text search speed.

This leads to few questions:

1. Suppose we have two different indexes but they contain same set and number(let's say 20) of fields( similar field names and data types). When two users searches simultaneously on these two indexes, will 20 fields be loaded on Cluster State as it has common fields or 40 fields will be loaded on Cluster State. If 40 fields are loaded on Cluster State, Is there a provision to make these fields common among indexes as they have similar properties(name and data type)

2. When 100,000 users simultaneously search on single index which contains 20 fields. Is it safe to assume, 100,000\*20 = 2,000,000 fields will be loaded in Cluster State?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 22, 2019, 8:34am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/33 "2019-01-22T08:34:14Z")

</div>

No and no.  
Cluster state changes with mapping changes not active searches.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 22, 2019, 8:40am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/34 "2019-01-22T08:40:14Z")

</div>

Thanks for the response

> [@Mark\_Harwood](#):
>
> Cluster state changes with mapping changes not active searches.

When 10 different indexes are searched simultaneously, does Cluster state load mapping of all 10 indexes?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 22, 2019, 9:12am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/35 "2019-01-22T09:12:22Z")

</div>

Cluster state is always loaded.

Have you tried benchmarking our suggestion of a single "copy\_to" field?  
Focus your efforts on minimising disk seeks. If you search a lot of indexed fields you are searching a lot of independent term collections and posting lists each requiring disk seeks. Minimise the number of indexed fields you search. Try SSDs to minimise the cost of each disk seek.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [February 1, 2019, 10:53am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/37 "2019-02-01T10:53:01Z")

</div>

Thanks for your inputs Mark,

"copy\_to" doesn't support features like Highlight which is a must in my use case.  
Although, I have benchmarked with the following parameters.

1. A single index with 5000 fields: A free text or rather search on all fields at once, takes time around 15s
2. 10 indexes with 500 each (unique at index level): A free text search on all these 10 indexes at once takes around 3s.  
I see almost 5x time increase in a single index with 5000 fields.

> [@Mark\_Harwood](#):
>
> They all add up

Although they are adding up, there is a difference in search speed in these two use cases.  
Can you please provide information on why there is a difference? Or am I missing something?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 1, 2019, 11:36am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/38 "2019-02-01T11:36:40Z")

</div>

> [@pranav24](#):
>
> "copy\_to" doesn't support features like Highlight

It does. You just need to set `require_field_match` to false on the fields you highlight.  
Highlighting is another operation that not surprisingly takes longer to do the more fields you throw at it.

> [@pranav24](#):
>
> Although they are adding up, there is a difference in search speed in these two use cases.

One is searching multiple indices in parallel. Of course dividing fields into multiple indices will not help you if all the fields can exist in the same document and users need to search for docs with `field A AND field B` type queries.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [February 1, 2019, 1:23pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/39 "2019-02-01T13:23:10Z")

</div>

Thanks Mark for the quick response.

> [@Mark\_Harwood](#):
>
> Of course, dividing fields into multiple indices will not help you if all the fields can exist in the same document and users need to search for docs with `field A AND field B` type queries.

Both of the above scenarios are not valid in our case. A single document is specific to only one index. So based on our benchmarking results as described earlier, we are planning to divide our single index containing 5000 unique fields into multiple indices having 500 unique fields each. The only reason we were earlier going with a single index containing 5000 fields was we didn't want to have a lot of indices.

> [@pranav24](#):
>
> A single index with 5000 fields: A free text or rather search on all fields at once, takes time around 15s

However, I am still not able to understand the 15s figure. I will explain my situation. The following is my Hardware configuration, Single Cluster with one master node and two data nodes. Each instance has 16GB RAM and 8GB Heap size.

1. We have created an index with 5000 fields. Each document indexed ranges from 100 fields to 150 fields at the most. We have indexed a total of 500 documents only. But the results (search on all fields- Free text search) obtained are not satisfactory. To be precise, it's around 15s which is very slow. Frankly speaking, I expected it to be in milliseconds. I am still curious why this much amount of time is taken for such a simple query.

2. On the same index as mentioned above, my search was slow even after mentioning the exact document ID as a parameter in the filter. A document ID is unique per document. What I understand is, this filter should bring down documents to be searched to only a single document and so the time taken should be in milliseconds only. however what I got was around 9s. I would like to know why there is not much variance in with and without a filter?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 1, 2019, 1:58pm UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/40 "2019-02-01T13:58:52Z")

</div>

> [@pranav24](#):
>
> I am still curious why this much amount of time is taken for such a simple query.

Given you were talking about highlighting earlier my money's on that.  
Probably needs some JSON query examples to know more.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [February 4, 2019, 5:33am UTC](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265/41 "2019-02-04T05:33:49Z")

</div>

Thanks Mark for the response.  
We are not doing any highlighting as part of this Benchmarking exercise.

```
{
"from" : 0, "size" : 10, 
"query": {
    "bool": 
   {"should": [ {
    "bool": {"should": [{
          "query_string": {
            "query":"\"test\"",
            "fields":[],
            "boost":"2000"
                           } }
                     , {
          "multi_match": {
            "query":"test",
            "type":"phrase",
            "boost":"500",
            "slop":"1",
            "fields":[]
}}, {
          "multi_match": {
            "query":"test",
            "type":"phrase",
            "boost":"200",
            "slop":"10000",
            "fields":[]
}},{
             
          "multi_match": {
           "query":"test ",
           "boost": "10", "operator":"and", "analyzer":"whitespace",
                  "fuzziness": "AUTO:4,7",
                  "prefix_length":1,
                  "max_expansions":2,
                         "fields":[]
}},{
             
          "multi_match": {
           "query":"test ",
           "boost": "10", "analyzer":"whitespace",
                         "fields":[]
}}],"minimum_should_match":1}}],"minimum_should_match":1,"filter": [{ "terms": { "field1.keyword" : ["30907cd80a174ad68dd0a2a2acdcd80e"]} } ]}}

```

This is a json query that is used for my benchmarking exercise. My requirement states, exact match should have highest priority, followed by phrase with one slop, phrase with high slop and fuzzy matches

[Previous page](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265.md?page=1)

[Next page](https://discuss.elastic.co/t/elasticsearch-single-index-vs-multiple-indexes/164265.md?page=3)
