# Multi tenancy with varying document mappings

**URL:** <https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 10:33am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508 "2019-01-09T10:33:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jameso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jameso/32/10182_2.png) [@jameso](https://discuss.elastic.co/u/jameso)\
**Post date:** [January 9, 2019, 10:33am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508/1 "2019-01-09T10:33:23Z")

</div>

We have an elasticsearch cluster where we store search data for multiple customers. Right now, we use an index per type of document and filter based on customer ID. This works well for us as all documents are the same.

We now have a requirement that customers should be able to create custom fields on top of the default ones, which are also searchable (customers search their data via a web app so we can control that). The problems around doing what we do now and say prefixing custom fields with the customer ID (way too many fields per index for example) seem like that wouldn't be a good solution.

The only feasible solution I can see is an index per customer with all of the additional overhead that includes (lots of partitions, hot/cold partitions, some large indexes vs some very small).

Are there any other possible ways of doing this that I should investigate?

---

<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 9, 2019, 10:53am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508/2 "2019-01-09T10:53:52Z")

</div>

You might be able to define a number of standard fields of different types and then map/translate customer field names to these. This will allow you to reduce the number of fields, but could affect relevancy calculation and would require translation at the application layer.

Having separate indices per customer would work for smaller number of customers but would scale badly.

---

<div class="post-metadata">

**Author:** ![jameso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jameso/32/10182_2.png) [@jameso](https://discuss.elastic.co/u/jameso)\
**Post date:** [January 9, 2019, 11:24am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508/3 "2019-01-09T11:24:03Z")

</div>

Thanks Christian. So you're essentially saying we could have generic fields like `custom_string_1` etc then just map each custom string field for a user to one of those?

---

<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 9, 2019, 11:24am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508/4 "2019-01-09T11:24:53Z")

</div>

Yes.

---

<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:** [February 6, 2019, 11:25am UTC](https://discuss.elastic.co/t/multi-tenancy-with-varying-document-mappings/163508/5 "2019-02-06T11:25:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
