Aggregations with dates & scripts

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 elasticsearch+unsubscribe@googlegroups.com.
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.

Hi Guillaume,

You should use doc[‘end_date’].value instead of doc[‘end_date’] .
See : Elasticsearch Platform — Find real-time answers at scale | Elastic

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

See : Elasticsearch Platform — Find real-time answers at scale | Elastic

I hope that those help you out.


Jun Ohtani
johtani@gmail.com
blog : http://blog.johtani.info
twitter : http://twitter.com/johtani

2014/12/04 7:47、Guillaume Alleon guillaume.alleon@gmail.com のメール:

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 elasticsearch+unsubscribe@googlegroups.com.
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 elasticsearch+unsubscribe@googlegroups.com.
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.

Hi Jun

Thanks a lot. That helped a lot. I also had to change:
doc['end_date'].value by doc["end_date"]

Cheers
Guillaume

On 6 December 2014 at 12:44, Jun Ohtani johtani@gmail.com wrote:

Hi Guillaume,

You should use doc[‘end_date’].value instead of doc[‘end_date’] .
See :
Elasticsearch Platform — Find real-time answers at scale | Elastic

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

See :
Elasticsearch Platform — Find real-time answers at scale | Elastic

I hope that those help you out.


Jun Ohtani
johtani@gmail.com
blog : http://blog.johtani.info
twitter : http://twitter.com/johtani

2014/12/04 7:47、Guillaume Alleon guillaume.alleon@gmail.com のメール:

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 elasticsearch+unsubscribe@googlegroups.com.
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 a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/EO8RWlNRJjA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
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.

--
PGP KeyID: 2048R/EA31CFC9 subkeys.pgp.net

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAE1e5yEfkKeghMRyahRA_C4c0u7k7pcsmuX2Bv3nQgxzujY5Hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.