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

给你一囗甜甜゛ 提交于 2019-12-09 07:35:00

问题


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?


回答1:


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.




回答2:


You can add this to your query fieldname:['' TO *]. This will be the equivalent of a NOT NULL check.

I got this from the post - Solr - Field Not Null Searches




回答3:


For a location field (solr.LatLonType), use the following filter query: -fieldName:[-90,-180 TO 90,180] (the coordinates outside this range are still invalid)




回答4:


Try this q= !fieldname:NULL this will be equivalent to Fieldvalue is NOT NULL.

Asked by STW 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?



来源:https://stackoverflow.com/questions/10722145/solr-how-do-i-construct-a-query-that-requires-a-not-null-location-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!