Hi,

Objects are flattened in index level. Nothing is indexed as “member” that’s why 
you get the exception.
Using doc[‘members.name'] instead of doc[‘members’] in script should work.


Masaru


On January 22, 2015 at 19:10:25, Jilles van Gurp ([email protected]) 
wrote:
> I'm trying to do a stats aggregation on the list length using a script but
> I'm getting errors. For this data,
>  
> PUT test_groups/group/1
> {
> "name":"1",
> "members":[
> {
> "name":"m1"
> }
> ]
> }
>  
> PUT test_groups/group/2
> {
> "name":"2",
> "members":[
> {
> "name":"m1"
> },
> {
> "name":"m2"
> }
> ]
> }
>  
> and this query:
>  
> GET test_groups/group/_search
> {
> "aggs": {
> "group_members": {
> "filter": {
> "exists": {
> "field": "members"
> }
> },
> "aggs": {
> "length": {
> "stats": {
> "script": "doc['members'].values.length"
> }
> }
> }
> }
> }
> }
>  
> I get an error stating that the members field does not exist in type group:
>  
> {
> "took": 4,
> "timed_out": false,
> "_shards": {
> "total": 5,
> "successful": 3,
> "failed": 2,
> "failures": [
> {
> "index": "test_groups",
> "shard": 2,
> "status": 500,
> "reason": "QueryPhaseExecutionException[[test_groups][2]:
> query[ConstantScore(cache(_type:group))],from[0],size[10]: Query Failed
> [Failed to execute main query]]; nested:
> GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No  
> field found for [members] in mapping with types [group]]]; "
> },
> {
> "index": "test_groups",
> "shard": 3,
> "status": 500,
> "reason": "QueryPhaseExecutionException[[test_groups][3]:
> query[ConstantScore(cache(_type:group))],from[0],size[10]: Query Failed
> [Failed to execute main query]]; nested:
> GroovyScriptExecutionException[ElasticsearchIllegalArgumentException[No  
> field found for [members] in mapping with types [group]]]; "
> }
> ]
> },
> "hits": {
> "total": 0,
> "max_score": null,
> "hits": []
> },
> "aggregations": {
> "group_members": {
> "doc_count": 0,
> "length": {
> "count": 0,
> "min": null,
> "max": null,
> "avg": null,
> "sum": null
> }
> }
> }
> }
>  
> Is there a way to do this?
>  
> Best regards,
>  
> Jilles
>  
> --
> 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/fcbce46c-6556-4e4e-b74a-2a4cbea915c6%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/etPan.54c1ac3b.7fdcc233.1877%40citra.local.
For more options, visit https://groups.google.com/d/optout.

Reply via email to