How to use exact match in multi_match using elasticsearch php


(Aravinthan Asokan) #1

Hi

I have successfully installed and setup the elasticsearch in php using elasticsearch-php client.

Now my challenge is how to do exact match inside multi_match for all fields.

My php call code below

$multi_match[] = array('multi_match' => array("query" => "xyz abc","operator" => "and", "fields" => array("a","b","c") ));
$params['body']['query']["filtered"]['query'] = $multi_match;
$response = $client->search($params);

how to use double quotes or exact each word search. I want to get result if any one field matches with both two words.

lets say if i have two record

Record 1

  1. field a = "xyz abc def" 2) field b = "gggg hhhh" 3) field c = "ssss"

Record 2

  1. field a = "xyzzyx abccba deffed" 2) field b = "gggg hhhh" 3) field c = "ssss"

if i use above multi_match i am getting both record. But i dont want like this i want only the exact match of two words. So i will only get Record 1 ..

How to do ?


(Thomas Decaux) #2

You have to tokenize (or just split) the query on your own, than once you have $words array, use a bool query with must and should sub queries:

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html


(system) #3