To achieve what you want you need to use two must clauses, one for body
and other for agency_id
. In case of body
you can specify your three conditions and use a minimum should match as 1. Should be something like this:
{
"size" : 10,
"query" : {
"function_score" : {
"query" : {
"bool" : {
"must" : {
"bool" : {
"should" : [ {
"query_string" : {
"query" : "word1 worrd2 word3 word4",
"fields" : [ "body" ],
"default_operator" : "and"
}
}, {
"query_string" : {
"query" : "word5 worrd6 word7",
"fields" : [ "body" ],
"default_operator" : "and"
}
}, {
"query_string" : {
"query" : "word8 worrd9 word10",
"fields" : [ "body" ],
"default_operator" : "and"
}
} ],
"minimum_should_match" : "1"
}
},
"must" : {
"query": {
"terms" : { "agency_id" : [ "id1", "id2", "id3" ]}
}
}
}
}
}
}
}
Just make sure you use some analyzer to generate tokens for each word inside body
. If you don't need any special feature you can just use standard analyzer.