elasticsearch - Elasticseach: Match phrase and term -
in elasticsearch, i'm constructing filtered query in order find documents contain both phrase , term. following query doesn't work. seems return results items in query array, if there 'or' operator applied.
edit: since i'm using php, following example php array.
'query' => [ 'filtered' => [ 'query' => [ 'match' => [ "post_content" => [ 'query' => ['ambulance services', 'veteran'], 'operator' => 'and', 'type' => 'phrase' ] ] ], 'filter' => [ ... ] ] ]
i have never seen syntax match query before can provide array query have done. did try out in version 0.90 , saw returned results second string. using json, tried this:
{ "query" : { "filtered" : { "query" : { "match" : { "post_content" : { "query" : [ "test string 1", "test string 2" ] } } } } } } if refer match query docs, and operator ensures terms in post_content field not taking positions of terms consideration. think match query boils down bool query each term in query represented clause. operator not quite want do.
i think following work want:
{ "query" : { "bool" : { "should" : [ { "match" : { "post_content" : { "type" : "phrase", "query" : "ambulance services" } } }, { "match" : { "post_content" : { "query" : "veteran" } } } ], "minimum_should_match" : 2 } } }
Comments
Post a Comment