Exception while using facet scripts

Hi,

Was trying to use histogram/terms facet to return some generated terms from
an indexed Date type field. Following is the facet query :

{
"query": {
"match_all": {}
},
"facets": {
"custom-facet": {
"terms": {
"field": "contentPublishedTime",
"size": 10,
"script":
"doc['contentPublishedTime'].date.dayOfWeek<6?'Weekday':'Weekend'"
}
}
},
"size": 1
}

where contentPublishedTime is a field mapped as a Date type.
The above query gives an exception

"{"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][0]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][0]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][4]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][4]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][6]: RemoteTransportException[[es_node_210_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][6]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][1]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][1]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][7]: RemoteTransportException[[es_node_210_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][7]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][8]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][8]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[GFSMHtIWQBGebimkqY5URA][lp-192.168.150.15-5444-lp-usaa-6-v3][2]: RemoteTransportException[[es_node_210_data][inet[/172.29.177.210:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][2]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][5]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][5]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][3]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][3]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }{[MKdBG4tcS0Sh-nd6WpkNgA][lp-192.168.150.15-5444-lp-usaa-6-v3][9]: RemoteTransportException[[es_node_102_data][inet[/172.29.177.102:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[lp-192.168.150.15-5444-lp-usaa-6-v3][9]: query[ConstantScore(NotDeleted(:))],from[0],size[1]: Query Failed [Failed to execute main query]]; nested: }]","status":500}"

I tried the same using histogram facets, as following :

{

"query": {

    "match_all": {}

},

"facets": {

    "histo1": {

        "histogram": {

            "key_script": "doc['contentPublishedTime'].date.dayOfWeek<6?'Weekday':'Weekend'",

            "value_script": "doc['anotherField'].value"

        }

    }

},

"size": 0

}

This one failed to with similar exception.

However, the following works:

{

"query": {

    "match_all": {}

},

"facets": {

    "histo1": {

        "histogram": {

            "key_script": "doc['contentPublishedTime'].date.dayOfWeek<6?55:56",

            "value_script": "doc['anotherField'].value"

        }

    }

},

"size": 0

}

Why cant I pass String values in script field? Any hints on how to achieve
this?

Thanks,
-- Sujoy.

--