# Match\_all syntax

**URL:** <https://discuss.elastic.co/t/match-all-syntax/10383>\
**Category:** Elasticsearch\
**Created:** [January 17, 2013, 6:41am UTC](https://discuss.elastic.co/t/match-all-syntax/10383 "2013-01-17T06:41:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [January 17, 2013, 6:41am UTC](https://discuss.elastic.co/t/match-all-syntax/10383/1 "2013-01-17T06:41:49Z")

</div>

Hi all

I just discovered the nice new feature match\_all but need some help. I was  
previously using a "filter" with "bool" and "should" with multiple "term"

here is an example  
{  
"query": {  
"filtered": {  
"query": {  
"multi\_match" : {  
"query" : "firstname lastname",  
"fields" : ["name", "email"]  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"account\_id": 1  
}  
},  
{  
"term": {  
"operator\_id": 1  
}  
}  
]  
}  
}  
}  
}  
}

the thing is I want to return results where both "firstname" and "lastname"  
exist in field "name" or both "firstname" and "lastname" exist in field  
email but it returns results where either match, im not sure if it makes a  
difference but name and email are arrays of strings

Regards

GX

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 17, 2013, 9:51am UTC](https://discuss.elastic.co/t/match-all-syntax/10383/2 "2013-01-17T09:51:34Z")

</div>

> the thing is I want to return results where both "firstname" and  
> "lastname" exist in field "name" or both "firstname" and "lastname"  
> exist in field email but it returns results where either match, im not  
> sure if it makes a difference but name and email are arrays of strings

You can't use multi\_match for this. Instead you can wrap two match  
clauses in a bool clause:

{  
"query" : {  
"filtered" : {  
"filter" : {  
"bool" : {  
"must" : [  
{  
"term" : {  
"account\_id" : 1  
}  
},  
{  
"term" : {  
"operator\_id" : 1  
}  
}  
]  
}  
},  
"query" : {  
"bool" : {  
"should" : [  
{  
"match" : {  
"name" : {  
"operator" : "and",  
"query" : "firstname lastname"  
}  
}  
},  
{  
"match" : {  
"email" : {  
"operator" : "and",  
"query" : "firstname lastname"  
}  
}  
}  
]  
}  
}  
}  
}  
}  
'

clint

--

---

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [January 17, 2013, 1:37pm UTC](https://discuss.elastic.co/t/match-all-syntax/10383/3 "2013-01-17T13:37:51Z")

</div>

Thanks Clint Ill try this method

On Thursday, January 17, 2013 11:51:34 AM UTC+2, Clinton Gormley wrote:

> > the thing is I want to return results where both "firstname" and  
> > "lastname" exist in field "name" or both "firstname" and "lastname"  
> > exist in field email but it returns results where either match, im not  
> > sure if it makes a difference but name and email are arrays of strings
> 
> You can't use multi\_match for this. Instead you can wrap two match  
> clauses in a bool clause:
> 
> {  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "bool" : {  
> "must" : [  
> {  
> "term" : {  
> "account\_id" : 1  
> }  
> },  
> {  
> "term" : {  
> "operator\_id" : 1  
> }  
> }  
> ]  
> }  
> },  
> "query" : {  
> "bool" : {  
> "should" : [  
> {  
> "match" : {  
> "name" : {  
> "operator" : "and",  
> "query" : "firstname lastname"  
> }  
> }  
> },  
> {  
> "match" : {  
> "email" : {  
> "operator" : "and",  
> "query" : "firstname lastname"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> '
> 
> clint

--

---

<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:** [July 6, 2017, 2:55am UTC](https://discuss.elastic.co/t/match-all-syntax/10383/4 "2017-07-06T02:55:55Z")

</div>

Closed on July 6, 2017, 2:55am UTC


