# Scripts during indexing

**URL:** <https://discuss.elastic.co/t/scripts-during-indexing/13470>\
**Category:** Elasticsearch\
**Created:** [September 5, 2013, 8:08am UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470 "2013-09-05T08:08:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 5, 2013, 8:08am UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/1 "2013-09-05T08:08:30Z")

</div>

Hi all,

I wonder if it is possible to use scripts within an index statement?

Thanks, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 5, 2013, 9:55am UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/2 "2013-09-05T09:55:41Z")

</div>

On Thu, Sep 05, 2013 at 08:08:30AM +0000, Adrian wrote:

All,

> I wonder if it is possible to use scripts within an index statement?

In my scripts, I'd like to perform comparison on fields which are mapped as  
"date". Given the documentation, these types are json strings, but handled as  
Java long types internally. Using MVEL as scripting, I've found operators for  
value comparison. Can someone tell on which types (String vs. long) this  
comparison is performed?

Thanks, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 5, 2013, 3:09pm UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/3 "2013-09-05T15:09:53Z")

</div>

Hi,  
I don't think you can use scripting while indexing. Scripting is more meant  
to on-the-fly generate content that you don't have when retrieving docs,  
for instance when searching, faceting etc.

Regarding the type question, it depends on where you load the value from.  
Have a look here:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting/). If you  
load it from disk, using the \_source syntax, then it's going to be a  
string, like in the json. If you load it from the document fields (field  
data), it's going to be a long.

Cheers  
Luca

On Thursday, September 5, 2013 11:55:41 AM UTC+2, Adrian wrote:

> On Thu, Sep 05, 2013 at 08:08:30AM +0000, Adrian wrote:
> 
> All,
> 
> > I wonder if it is possible to use scripts within an index statement?
> 
> In my scripts, I'd like to perform comparison on fields which are mapped  
> as  
> "date". Given the documentation, these types are json strings, but handled  
> as  
> Java long types internally. Using MVEL as scripting, I've found operators  
> for  
> value comparison. Can someone tell on which types (String vs. long) this  
> comparison is performed?
> 
> Thanks, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 5, 2013, 3:48pm UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/4 "2013-09-05T15:48:14Z")

</div>

On Thu, Sep 05, 2013 at 08:09:53AM -0700, Luca Cavanna wrote:

Luca,

> Regarding the type question, it depends on where you load the value from.  
> Have a look here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting/). If you  
> load it from disk, using the \_source syntax, then it's going to be a  
> string, like in the json. If you load it from the document fields (field  
> data), it's going to be a long.

So, referencing the date field in an update (using ctx.\_source.) the  
comparison operators "\<,\>" should suffice.

Best, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 5, 2013, 6:00pm UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/5 "2013-09-05T18:00:33Z")

</div>

Scripting is meant to be used during querying time. What are you looking to  
achieve? If you are looking at changing the content that is indexed, you  
can perhaps use a custom filter/tokenizer/analyzer or modify the data at  
the client (index) side.

Cheers,

Ivan

On Thu, Sep 5, 2013 at 1:08 AM, Adrian [google@core.kyubu.de](mailto:google@core.kyubu.de) wrote:

> Hi all,
> 
> I wonder if it is possible to use scripts within an index statement?
> 
> Thanks, Adrian
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_2](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Adrian\_2](https://discuss.elastic.co/u/Adrian_2)\
**Post date:** [September 6, 2013, 11:36am UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/6 "2013-09-06T11:36:00Z")

</div>

On Thu, Sep 05, 2013 at 11:00:33AM -0700, Ivan Brusic wrote:

Ivan,

> Scripting is meant to be used during querying time. What are you looking to  
> achieve? If you are looking at changing the content that is indexed, you  
> can perhaps use a custom filter/tokenizer/analyzer or modify the data at  
> the client (index) side.

I have a quite huge number of documents (\> 2 Bio.). When doing an overview of  
these using facets on a certain field, the querying time is just too long. So I  
tried to build a second index, holding this (aggregated) data. The scripting  
was intented to update th relvant fields for this index (such as first seen,  
last seen, etc.)

Best regards, Adrian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:17am UTC](https://discuss.elastic.co/t/scripts-during-indexing/13470/7 "2017-07-06T02:17:51Z")

</div>


