Reputation: 6284
Is it possible to get number of "shoulds" matched or return constant weight per each should matched. For example, if I have a bool query like this:
"query": {
"bool": {
"should": [
{ "match": { "last_name": "Shcheklein" }},
{ "match": { "first_name": "Bart" }}
]
}
}
I would like to get:
score == 1
if one of the fields (last_name
, first_name
) matches (even in a fuzzy sense)
score == 2
if both fields match
And is it possible to get a list of fields matched?
Upvotes: 4
Views: 1798
Reputation: 17441
you could probably use constant score to achieve this and use highlighting to figure out the fields that matched.
Example :
{
"query": {
"bool": {
"disable_coord": true,
"should": [
{
"constant_score": {
"query": {
"match": {
"last_name": "Shcheklein"
}
},
"boost": 1
}
},
{
"constant_score": {
"query": {
"match": {
"first_name": "bart"
}
},
"boost": 1
}
}
]
}
}
}
Upvotes: 3