# Determine count of fields in a document

**URL:** <https://discuss.elastic.co/t/determine-count-of-fields-in-a-document/360946>\
**Category:** Elasticsearch\
**Tags:** painless, runtime-fields\
**Created:** [June 6, 2024, 9:35am UTC](https://discuss.elastic.co/t/determine-count-of-fields-in-a-document/360946 "2024-06-06T09:35:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lolabam](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@lolabam](https://discuss.elastic.co/u/lolabam)\
**Post date:** [June 6, 2024, 9:35am UTC](https://discuss.elastic.co/t/determine-count-of-fields-in-a-document/360946/1 "2024-06-06T09:35:26Z")

</div>

I'm new to painless scripts. I'd like to create a runtime field that returns the count of fields in a document. Can anyone help with the right script to use?

---

<div class="post-metadata">

**Author:** ![jessgarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessgarson/32/129841_2.png) [@jessgarson](https://discuss.elastic.co/u/jessgarson)\
**Post date:** [June 7, 2024, 10:39pm UTC](https://discuss.elastic.co/t/determine-count-of-fields-in-a-document/360946/2 "2024-06-07T22:39:56Z")

</div>

Thanks for reaching out. [Our documentation](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-runtime-fields.html) might be a good starting point here. Do you have a code sample you are working on that you can share?
