# Elastic mapping flattened vs field wise

**URL:** <https://discuss.elastic.co/t/elastic-mapping-flattened-vs-field-wise/362151>\
**Category:** Elasticsearch\
**Created:** [June 27, 2024, 11:33am UTC](https://discuss.elastic.co/t/elastic-mapping-flattened-vs-field-wise/362151 "2024-06-27T11:33:30Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [July 2, 2024, 1:42pm UTC](https://discuss.elastic.co/t/elastic-mapping-flattened-vs-field-wise/362151/3 "2024-07-02T13:42:04Z")

</div>

> [@Moni\_Hazarika](#):
>
> What is the best way to store it in Elastic like a flattened structure for better searching or have individual field mapping like below? What are your thoughts? pros and cons of each if any?

I would say that it is best to have each field mapped with the correct data type, the _flattened_ data type should be used when you have an object with a lot of unkown keys.

It should not be used to map the entire document as mentioned in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/flattened.html).

> The `flattened` mapping type should **not** be used for indexing all document content, as it treats all values as keywords and does not provide full search functionality. The default approach, where each subfield has its own entry in the mappings, works well in the majority of cases.

---

_[View the full topic](https://discuss.elastic.co/t/elastic-mapping-flattened-vs-field-wise/362151)._
