Testing a field against an array of choices


(Andrei) #1

What is the best way to test a field (not_analyzed one) to see if it
matches a given array of choices, similar to how SQL's IN clause
works? So far, I've been able to do it via an OR'ed "field" query, but
wonder if there is a more efficient method:

{ query:
{ filtered:
{ query:
{ query_string:
{ query: 'coffee'
, use_dis_max: true
, default_operator: 'AND'
, fields: [ 'title', 'desc' ] }
}
, filter:
{ query:
{ field:
{ user: 'user1 OR user2 OR user3' }
}
}
}
}
}


(Andrei) #2

Never mind, I found "terms" filter. :slight_smile:

On Sep 7, 12:09 pm, Andrei and...@zmievski.org wrote:

What is the best way to test a field (not_analyzed one) to see if it
matches a given array of choices, similar to how SQL's IN clause
works? So far, I've been able to do it via an OR'ed "field" query, but
wonder if there is a more efficient method:

{ query:
{ filtered:
{ query:
{ query_string:
{ query: 'coffee'
, use_dis_max: true
, default_operator: 'AND'
, fields: [ 'title', 'desc' ] }
}
, filter:
{ query:
{ field:
{ user: 'user1 OR user2 OR user3' }
}
}
}
}

}


(system) #3