First you've got to understand how Elasticsearch (and especially Lucene) store your data.
Elasticsearch's naming convention "index" and "type" is a bit misleading and most likely not what you first thought!
If you create a type (id, field1, field2
) within an index in Elasticsearch, it will create something similar to a SQL Table:
id | field1 | field2
-------------------------
string | int | boolean
What you might not expect is, what happens when you add a second type (id, type2field
) to that index. The index mapping will become:
id | field1 | field2 | type2field
--------------------------------------
string | int | boolean | string
This happens, because there's no type mapping - even if Elasticsearch will make it look like that. There's only a mapping at index level! This way, you will most likely end up having a lot of empty fields.
Though in general and especially for a multi tenency setup, you should create an index per class - not type! You should use the type for separating similar shaped data, i.e. use types for your tenants. Or add an additional field to your mapping for identifying the tenant.
Read more about it here: https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping.html#_type_takeaways