# How to add custom fields uppon indexing

**URL:** <https://discuss.elastic.co/t/how-to-add-custom-fields-uppon-indexing/1967>\
**Category:** Elasticsearch\
**Created:** [June 4, 2015, 7:45pm UTC](https://discuss.elastic.co/t/how-to-add-custom-fields-uppon-indexing/1967 "2015-06-04T19:45:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![j3romee](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@j3romee](https://discuss.elastic.co/u/j3romee)\
**Post date:** [June 4, 2015, 7:45pm UTC](https://discuss.elastic.co/t/how-to-add-custom-fields-uppon-indexing/1967/1 "2015-06-04T19:45:45Z")

</div>

hey there,  
I'm new to elasticsearch (Awesome product by the way 🙂 )

I am using the FS river plugin to index files on a filesystem.

I want to add customs fields inferred from other fields of the indexed file.

Let me illustrate this by an example :  
Suppose we index a file named test.pdf.  
FS river will create a document with a \_source field containing a field named filename.  
I'd like to add a new field named type (to \_source or whatever) that will use the filename to determine the filetype (using the extension)

So at the end, the returned document would have a filename field (test.pdf) and a type field (pdf) infered from the filename.

I can already do this on query with the scripts\_fields but this mean an overhead on every request. Is there a way to transfert that logic on indexing ?

Thanks in advance,

Jerome

P.S: I know rivers are now deprecated, I just want to index a filesystem. What are the alternatives in the new version of elasticsearch. The documentation isn't really explicit about indexing a filesystem.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 6, 2015, 12:29pm UTC](https://discuss.elastic.co/t/how-to-add-custom-fields-uppon-indexing/1967/2 "2015-06-06T12:29:33Z")

</div>

You should into using Logstash. It's not deprecated and it's easy to add fields based on the values of existing fields.

---

<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:** [July 6, 2017, 12:09am UTC](https://discuss.elastic.co/t/how-to-add-custom-fields-uppon-indexing/1967/3 "2017-07-06T00:09:13Z")

</div>


