Lawrence Cooke
Lawrence Cooke

Reputation: 1597

Cloudsearch bounding box filter

I have the following CloudSearch Query

$query = array(
'query' => '(and expiry:[' . $time . ',} updatetime:[100,} type:\'all\')',
'queryParser' => 'structured',
'queryOptions' => '{"defaultOperator":"and"}',
'sort' => 'distance asc',
'return'=>'_all_fields,_score,distance',
'size' => 5000,
'expr'=> '{"distance":"haversin(' . $lat . ',' . $lon . ',location.latitude,location.longitude)"}',
'start'=>$start,
'fq'=>'location:[\'35.628611,-120.694152\',\'35.621966,-120.686706\']'

);

The query works except for the FQ part, the intention is that the fq would restrict the results to within a bounding box area. but despite having it there, its not restricting the results. results far outside that region are returning, What do I need to change this to make it work correctly?

Upvotes: 4

Views: 870

Answers (1)

Lawrence Cooke
Lawrence Cooke

Reputation: 1597

I have the solution for this issue

Although the aws docs refer to it in examples as fq its actually filterQuery

also note that the location point order is top-left, bottom-right

$query = array(
'query' => '(and expiry:[' . $time . ',} updatetime:[100,} type:\'all\')',
'queryParser' => 'structured',
'queryOptions' => '{"defaultOperator":"and"}',
'sort' => 'distance asc',
'return'=>'_all_fields,_score,distance',
'size' => 5000,
'expr'=> '{"distance":"haversin(' . $lat . ',' . $lon .          ',location.latitude,location.longitude)"}',
'start'=>$start,
'filterQuery'=>'location:[\'35.628611,-120.694152\',\'35.621966,-120.686706\']'

 );

Upvotes: 3

Related Questions