Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Cloudsearch : Filter if exists

I have an amazon cloudsearch domain. The aim is to filter if the field 'language' exists. Not all objects have a language, and I want to have the ones which do have a language filtered, but the ones that do not have any language to also be returned.

I want to filter with ( or language:'en' language:null )

However null cannot be passed within a string.

Is this possible? If so how would it be done.

like image 532
Nyxter Avatar asked Oct 27 '14 16:10

Nyxter


People also ask

Is Amazon CloudSearch deprecated?

Amazon search is deprecated: Amazon search service is no longer supported. To set up a search functionality on your site(s), configure one of the three built-in search services instead. Amazon Cloud Search is deprecated in Sitefinity 13.3.

What are the benefits of Amazon CloudSearch?

Amazon CloudSearch lets customers add search capability without needing to manage hosts, traffic and data scaling, redundancy, or software packages. Users pay low hourly rates only for the resources consumed.

What is CloudSearch in AWS?

Amazon CloudSearch is a managed service in the AWS Cloud that makes it simple and cost-effective to set up, manage, and scale a search solution for your website or application. Amazon CloudSearch supports 34 languages and popular search features such as highlighting, autocomplete, and geospatial search.


2 Answers

If you are willing to use the Lucene query parser you can express your query like this:

(*:* OR -language:*) OR language:en

Note: The funky (*:* OR ...) construct is necessary because of the way Lucene treats negated OR clauses.

In general, you can filter by existence / non-existence of a field with the Lucene query parser:

All documents containing field: field:[* TO *]

All documents not containing field: -field:[* TO *]

Note: If field is textual (text or literal datatypes) you don't need range queries and you can shorten the above to:

field:* and -field:*

like image 152
maxa Avatar answered Oct 08 '22 12:10

maxa


I looked elsewhere aswell, it seems :

The simplest way to do that, is to set a default value for the field, and then use that value for your null.

For example, set the default to the string "null", then you can easily test for that.

I believe you can add a default value, and re-index, and that should reapply the default.

like image 24
Nyxter Avatar answered Oct 08 '22 11:10

Nyxter