# Scripting in java

**URL:** <https://discuss.elastic.co/t/scripting-in-java/16134>\
**Category:** Elasticsearch\
**Created:** [March 4, 2014, 9:35am UTC](https://discuss.elastic.co/t/scripting-in-java/16134 "2014-03-04T09:35:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernard\_CHAMBON](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@Bernard\_CHAMBON](https://discuss.elastic.co/u/Bernard_CHAMBON)\
**Post date:** [March 4, 2014, 9:35am UTC](https://discuss.elastic.co/t/scripting-in-java/16134/1 "2014-03-04T09:35:28Z")

</div>

Hi,

I'm trying to play with scripting (in java) and that's not obvious to me

1/ The smallest example don't compile due to doc().field not found

public class Ex2ScriptFactory implements NativeScriptFactory {  
@Override  
public ExecutableScript newScript (@Nullable Map\<String,Object\> params) {  
return new Ex2Script(params);  
}  
}

public class Ex2Script extends AbstractSearchScript {  
public Ex2Script(@Nullable Map\<String,Object\> params) {  
String afield = (String)params.get("field");  
DocLookup docLookup=doc();  
doc().field(afield);  
}

@Override  
public Object run(){  
return(null);  
}  
}

> javac -cp ./elasticsearch-1.0.1/lib/elasticsearch-1.0.1.jar  
> scripting/ex2/\*.java  
> scripting/ex2/Ex2Script.java:28: cannot find symbol  
> symbol : method field(java.lang.String)  
> location: class org.elasticsearch.search.lookup.DocLookup  
> doc().field(afield);

It the same with e.g. doc().numeric(...)

Do I miss something ?

2/ More 'high level' question  
giving a set of documents (events), I'd like to iterate over them to  
compute values and provide new fields  
Is this acceptable in elasticsearch, is scripting available for that ?  
(for example to compute the duration between two events)

Best regards

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b888da10-631c-4d06-9f9a-1f2f2f0116d6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b888da10-631c-4d06-9f9a-1f2f2f0116d6%40googlegroups.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, 1:45am UTC](https://discuss.elastic.co/t/scripting-in-java/16134/2 "2017-07-06T01:45:53Z")

</div>

Closed on July 6, 2017, 1:45am UTC


