Match_all syntax

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

--

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

--

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

--