# Complex nested query with wildcards

**URL:** <https://discuss.elastic.co/t/complex-nested-query-with-wildcards/117418>\
**Category:** Elasticsearch\
**Created:** [January 29, 2018, 8:55am UTC](https://discuss.elastic.co/t/complex-nested-query-with-wildcards/117418 "2018-01-29T08:55:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeiPetrov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergeipetrov/32/27127_2.png) [@SergeiPetrov](https://discuss.elastic.co/u/SergeiPetrov)\
**Post date:** [January 29, 2018, 8:55am UTC](https://discuss.elastic.co/t/complex-nested-query-with-wildcards/117418/1 "2018-01-29T08:55:24Z")

</div>

Hello, I stack with one problem. I have an element which contains array of nested objects. For example I create a new index.  
**GET** /test/test/\_mapping  
{  
"test": {  
"mappings": {  
"test": {  
"properties": {  
"columnName": {  
"type": "text"  
},  
"list": {  
"type": "nested",  
"properties": {  
"black cat": {  
"type": "long"  
},  
"red fox": {  
"type": "long"  
},  
"white cat": {  
"type": "long"  
},  
"white dog": {  
"type": "long"  
}  
}  
},  
"name": {  
"type": "text"  
}  
}  
}  
}  
}  
}

This "list" can be modified at any time, so the customer can add a new objects. ("brown dog", etc.)  
For example one of the objects can looks like:  
{  
"\_index": "test",  
"\_type": "test",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"name": "First example",  
"columnName": "Something",  
"list": [  
{  
"white cat": 1  
}  
]  
}  
}

I need to create query which can sum all numbers in fields which are suitable for the regexp. For example, "\*dog".  
If we have the following element:  
{  
"\_index": "test",  
"\_type": "test",  
"\_id": "3",  
"\_score": 1,  
"\_source": {  
"name": "Third example",  
"columnName": "Something",  
"list": [  
{  
"white dog": 3,  
"black dog": 2,  
"white cat": 1  
}  
]  
}  
}  
From the query with "list.\*dog" wildcard I must get 5 (3 + 2).

I read about Multi\_Match query which supports wildcard in name of fields, but in this situation I need to know the value. And I also saw a Range query in which I can say that field must be greater than 0, but Range query doesn't support wildcard. But how to combine these queries and count the sum of the fields, I don't know.

---

<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:** [February 26, 2018, 8:55am UTC](https://discuss.elastic.co/t/complex-nested-query-with-wildcards/117418/2 "2018-02-26T08:55:37Z")

</div>

Closed on February 26, 2018, 8:55am UTC

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