Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr - How do I construct a query that requires a NOT NULL Location field

I have a Solr index with a set of coordinates stored as a Location type; I would like to query for documents where this field has a non-null value.

What is the query syntax to perform the NOT NULL check on a Location field?

like image 687
STW Avatar asked May 23 '12 14:05

STW


People also ask

What is Q in Solr query?

Solr provides Query (q parameter) and Filter Query (fq parameter) for searching. The query (q parameter), as the name suggests, is the main query used for searching. Example. q = title:james. Filter queries are used alongside query (q parameter) to limit results of queries using additional filters.

How do you directly query Solr?

Trying a basic queryThe main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.

What is the default return type of Solr request?

The default value is 0 . In other words, by default, Solr returns results without an offset, beginning where the results themselves begin.

What is Solr index field?

"indexed" is used for search or query, the "lookup" portion of processing a query request. Once the search/query/lookup is complete and a set of documents is selected, "stored" is the set of fields whose values are available for display or return with the Solr response.


1 Answers

The canonical way is this:

fieldName:[* TO *] 

Using a '' on the left side as Paige Cook suggested will probably work too but I don't trust it as much as I do the above. And since this is to a Location field, you will probably have to do this against one of the two underlying actual fields versus this logical composite field. They start with fieldName and end with some sort of numeric suffix; look in the Schema Browser to see what the actual name is.

An important thing to be aware of here is that a query like this is expensive for Solr to do as it much do a full index scan on this field. If you have many distinct location field values (thousands on up?), then this is a big deal. If you do this in a filter query, then it will be cached and it's perhaps moot. If you want this query to run fast, then at index time you should index a boolean field to indicate if there is a value in this field or not.

like image 146
David Smiley Avatar answered Sep 28 '22 10:09

David Smiley