# Query on array

**URL:** https://discuss.elastic.co/t/query-on-array/205899
**Category:** Elasticsearch
**Tags:** painless
**Created:** [October 30, 2019, 3:45pm UTC](https://discuss.elastic.co/t/query-on-array/205899 "2019-10-30T15:45:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Segfault](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Segfault](https://discuss.elastic.co/u/Segfault)
#### Post date: [October 30, 2019, 3:45pm UTC](https://discuss.elastic.co/t/query-on-array/205899/1 "2019-10-30T15:45:24Z")

</div>

Hello world,

I'm trying to query with a filter to restrict array size. (Only get the results that have more than 1 object inside the transactions array)  
I can't manage to get it working. I hope some people here have some ideas to help me.

My mapping is the following:

```
{
	"properties": {
		"userId": {"type": "keyword"},
		"shopId": {"type": "keyword"},
		"transactions": {
			"type": "nested",
			"properties": {
				"date": {"type": "text"},
				"commissionStatus": {"type": "text"},
				"commissionAmount": {"type": "float"},
				"commissionAmountTicker": {"type": "text"},
				"saleAmount": {"type": "float"},
				"saleCurrencyTicker": {"type": "text"},
				"id": {"type": "text"},
				"type": {"type": "text"},
				"network": {"type": "text"}
			}
		}
	}
}

```

I'm trying to do the following query:

```
{
	"query": {
		"bool": {
		  "must": [{
		    "match": {"shopId":"5109468509503488"}
		  }],
		  "filter": [{
	        "range" : {
	            "@timestamp" : {
	                "gte": "now-7d/d",
	                "lte": "now/d"
	            }
	        }
		  },
		  {
		  	"script": {
	        	"script": {
	        		"source": "doc['transactions'].length >= 1",
	        		"lang": "painless"
	        	}
	        }
		  }]
		}
	},
	"size": 1
}

```

But I get an error:

> "failed\_shards": [  
> {  
> "shard": 0,  
> "index": "transactions",  
> "node": "TpzdGPfjTjejIAnk4mSgEg",  
> "reason": {  
> "type": "script\_exception",  
> "reason": "runtime error",  
> "script\_stack": [  
> "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",  
> "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",  
> "doc['transactions'].length \>= 1",  
> " ^---- HERE"  
> ],  
> "script": "doc['transactions'].length \>= 1",  
> "lang": "painless",  
> "caused\_by": {  
> "type": "illegal\_argument\_exception",  
> "reason": "No field found for [transactions] in mapping with types "  
> }  
> }  
> }  
> ]

Thank you for your help.

---

<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: [November 27, 2019, 3:45pm UTC](https://discuss.elastic.co/t/query-on-array/205899/2 "2019-11-27T15:45:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
