4

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?

Lawrence Cooke
  • 1,567
  • 3
  • 26
  • 52
  • Do you have the actual GET request URL that is ultimately created from your query? I'd be curious to see what sort of location fq it includes. – alexroussos Jan 29 '15 at 16:02
  • I'm not sure I can give you that, I am using the official PHP api for AWS, so it all gets bundled up into a call made by the API, I will trace through the API to see if I can find and log the call made to amazon – Lawrence Cooke Jan 30 '15 at 01:59
  • If you're unable to get it through logging, you could also use something like Charles (http://www.charlesproxy.com) to log traffic. – alexroussos Jan 30 '15 at 16:03
  • I have traced the call through guzzle, and logged the request sent in the guzzle send function, that I see is that the fq is not there. its in the originating query, but in the send call, its not there. I am not sure why that would be? – Lawrence Cooke Feb 02 '15 at 07:02
  • Great, that narrows things down a bit. I'd play around with setting some different, simpler fq values; do any of them work or is fq totally broken in the library? One other thing to check: are you using the latest API version (2013)? The fq param is something that didn't exist in the older (2011) API – alexroussos Feb 02 '15 at 19:33
  • I tried a simpler query changing the fq to : 'fq'=>'country:US', and it still doesnt show up on the send, I have updated to the latest version from github with the same thing happening. I am using v 2013 , is there something wrong with the way i am structuring the query? just to verify that it wasnt in there, I change the field name in the query to a fake one which should return an error, but no error occurred – Lawrence Cooke Feb 02 '15 at 22:30
  • It sounds like a possible bug, although it would be pretty glaring if fq was completely broken. I'm not at all familiar with PHP or I'd poke around a bit. Anyway, looks like you already posted to AWS (https://forums.aws.amazon.com/thread.jspa?threadID=170873&tstart=0) which was going to be my next suggestion. – alexroussos Feb 03 '15 at 19:52
  • You're welcome. Sorry we couldn't get to the bottom of it... hopefully someone on the AWS forums can help. If they do, please post back here -- I'd be curious to see and it may help people in the future. – alexroussos Feb 04 '15 at 18:39

1 Answers1

3

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\']'

 );
Lawrence Cooke
  • 1,567
  • 3
  • 26
  • 52