Search code examples
amazon-web-servicesamazon-cloudsearch

CloudSearch - Return results when a field does not exist


Is there a CloudSearch structured query to return results that do not have a value within a field? For example, I have a field called target_date that does not always have a value and I want to return all results with no target_date. This field is not zero'd out or set to a default; it doesn't exist at all for items without the date.

There is another case too. I need to return all results after a target_date AND include any results without an existing date. The structured query I am using is target_date:['2000-03-03T00:00:00Z',}. The query to find non-existing dates should work with an and operator, like: (and target_date:['2000-03-03T00:00:00Z',} [QUERY_GOES_HERE])


Solution

  • I believe you're asking the same thing as Amazon Cloudsearch : Filter if exists

    To summarize the options from there:

    1. Add a new boolean field called 'has_target_date'
    2. Set a default target_date (eg 1/1/1970) to mean that it doesn't exist
    3. The hack: (range field=target_date [0,})

    Any of those options should work with the QUERY_GOES_HERE portion of your question.