# Can the field type (e.g. "flattened") be specified at time of indexing?

**URL:** <https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671>\
**Category:** Elasticsearch\
**Created:** [March 2, 2022, 8:06pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671 "2022-03-02T20:06:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [March 2, 2022, 8:06pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/1 "2022-03-02T20:06:35Z")

</div>

I know I can specify that a specific field has the type "flattened" ([Flattened field type | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/flattened.html)) by specifying that in the index \_mapping but is there a way to do that when indexing?

I want the type of `a` to be `flattened`.  
`curl -XPUT -H 'Content-type: application/json' --data-binary '{"a":{"p1":"foo"}}' localhost:9200/test1/_doc/1`

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 2, 2022, 11:20pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/2 "2022-03-02T23:20:11Z")

</div>

If you have created the index with that mapping before indexing, then it'll be applied.

Otherwise Elasticsearch will do a best guess at mapping (ie [dynamic mappings](https://www.elastic.co/guide/en/elasticsearch/reference/8.0/dynamic-mapping.html)).

---

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [March 9, 2022, 5:04pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/3 "2022-03-09T17:04:59Z")

</div>

Thanks, okay. And unfortunately there's no way to make a field look "flattened" so there's no way for that type to be automatically used without an explicit mapping.

> **[Dynamic field mapping | Elasticsearch Guide \[8.0\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.0/dynamic-field-mapping.html)**

---

<div class="post-metadata">

**Author:** ![casterQ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/casterq/32/93257_2.png) [@casterQ](https://discuss.elastic.co/u/casterQ)\
**Post date:** [March 10, 2022, 3:54am UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/4 "2022-03-10T03:54:00Z")

</div>

does `dynamic_templates` meet your needs？

---

<div class="post-metadata">

**Author:** ![Jamshid](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@Jamshid](https://discuss.elastic.co/u/Jamshid)\
**Post date:** [March 22, 2022, 9:24pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/5 "2022-03-22T21:24:50Z")

</div>

Thanks, `dynamic_templates` would work but I'm trying to index a `flattened` field **without** updating the schema mappings.

I was trying to deploy a new version of my application which adds this field without requiring a separate, manual schema update. But I guess there's no way.

---

<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:** [April 19, 2022, 9:24pm UTC](https://discuss.elastic.co/t/can-the-field-type-e-g-flattened-be-specified-at-time-of-indexing/298671/6 "2022-04-19T21:24:59Z")

</div>

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