What if all filter not applied ? filter with null FIELD VALUE not NULL value in DOC

I have search for subjects..Teacher can add multiple subjects and students can search thode subject and can apply filter on resulted data..student can filter by LEVEL, CURRICULUM, LOCATION..

My query is what if student has not applied LOCATION filter?

Of i pass Location string in filter everything works fine for me..but when i do not apply LOCATION filter..it gives me No text specified for text query..

here is my query :

    $client = ClientBuilder::create()->build();
    $location = $request->location;
    $level = $request->level;
    $curriculum = $request->curriculum;
    $params = [
        'index' => 'tutors',
        'body'  => 
     	[
            "query" => [
                "bool" => [
                	"must" => [
                		[ "term" => [ "approved" => 1 ]],
                    	[ "match" => [ "country_en_name" =>  $location ]],
                     	[ "match" => [ "local_rates.levels" =>  $level ]],
                     	[ "match" => [ "local_rates.curriculums" =>  $curriculum ]],
                	]
                ],
            ]
        ]
    ];
    $search = $client->search($params);

I have also tried like this for NULL or EMPTY value

    $client = ClientBuilder::create()->build();
    $location = $request->location;
    $level = $request->level;
    $curriculum = $request->curriculum;
    $params = [
        'index' => 'tutors',
        'body'  => 
     	[
            "query" => [
                "bool" => [
                	"must" => [
                		[ "term" => [ "approved" => 1 ]],
                    	$location && $location != null ? [ "match" => [ "country_en_name" =>  $location ]] : '',
                     	$level && $level != null ? [ "match" => [ "local_rates.levels" =>  $level ]] : '',
                        $curriculum && $curriculum != null ? [ "match" => [ "local_rates.curriculums" =>  $curriculum ]] : '',
                	]
                ],
            ]
        ]
    ];
    $search = $client->search($params);

Can anyone helps me out?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.