在solr查询中使用不相等或丢失
寻找一种将以下表达式转换为solr查询的方法。
isnull(field)或field!= 1
我尝试了几件事,
field:1或-field:*
- ( - 字段:1和field:1 and field: *)
( - 字段:1或(*:* - field:*))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Solr 标准查询解析器不支持在字段中搜索空/空值。在这种情况下,需要否定过滤器(排除字段中具有任何值的文档),以便查询保持有效。
但是,使用 范围查询在否定子查询中使用通配符时,最好防止出现不一致的行为。
因此
ISNULL(field)
变为-field:[* TO *]
另外,在同一个 fq 参数中应用过滤器和否定过滤器时,需要添加
*:*
并确保第一个-
运算符仅适用于使用括号的第一个过滤器,否则 OR 将无法正确应用。因此,如果要将此过滤器与其他过滤器组合,请确保过滤器与结果集相交(假设过滤器应适用于所有文档):请注意,这相当于:
这意味着您只需要该部分(只要
< val>
不为 null,即与 1 不同的值匹配包括 null/空值):Solr Standard Query Parser does not support searching a field for empty/null value. In this situation the filter needs to be negated (exluding documents having any value in the field) so that the query remains valid.
However, using a range query is preferred to prevent inconsitent behaviors when using wildcard within negative subqueries.
So
ISNULL(field)
becomes-field:[* TO *]
Also, when applying a filter and a negated filter in the same fq param, you need to add
*:*
on the latter and ensure the first-
operator applies to only the first filter using parentheses, otherwise the OR won't apply properly, . So if this filter is to be combined with others, ensure the filter intersects the resultset (assuming that filter should apply to all documents) :Note this is equivalent to :
Which means you only need that part (as long as
<val>
is not null, ie. matches with a value different than 1 includes null/empty values) :