Hi Guillaume,

You should use doc[‘end_date’].value instead of doc[‘end_date’] .
See : 
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html#_document_fields

And you should use 3600000 instead of 3600. 
Date type is a long number representing UTC milliseconds since the epoch.

See : 
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#date

I hope that those help you out.


------------
Jun Ohtani
[email protected]
blog : http://blog.johtani.info
twitter : http://twitter.com/johtani

> 2014/12/04 7:47、Guillaume Alleon <[email protected]> のメール:
> 
> Hi 
> 
> I have  a mapping which is having the following 2 properties:
>                     "start_date": {
>                         "format": "dateOptionalTime",
>                         "type": "date"
>                     },
>                     "end_date": {
>                         "format": "dateOptionalTime",
>                         "type": "date"
>                     },
> 
> I want to create an histogram for durations with 1 hour intervals by doing  
> this:
> 
> curl -XGET 'http://localhost:9200/myindex/travels/_search_search?pretty' -d '
> {
> 
>     "aggs": {
> 
>         "duration": {
> 
>             "histogram": {
> 
>                 "interval": 1,
> 
>                 "script": "(doc['end_date']-doc['start_date'])/3600"
> 
>             }
> 
>         }
> 
>     }
> 
> }'
> 
> I got the following error:
> 
> GroovyScriptExecutionException[MissingPropertyException[No such property: 
> end_date for class: Script1]]; }{[B4xwr8FCSnOLkrNAVhgHMg][gequest][2]: 
> QueryPhaseExecutionException[[myindex][2]: 
> query[ConstantScore(cache(_type:travels))],from[0],size[10]: Query Failed 
> [Failed to execute main query]]; nested: 
> GroovyScriptExecutionException[MissingPropertyException[No such property: 
> end_date for class: Script1]]; }
> 
> I have the same error for start_date.
> 
> 
> 
> Any idea what I am doing wrong ?
> 
> 
> 
> Cheers
> 
> Guillaume
> 
> 
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elasticsearch/6ca86563-5881-4004-af35-a258841ec326%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/C3D0F8B9-CAA7-46A9-ACC0-505D6C0F22F8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to