How to OR null value in Apache Solr query?

走远了吗. 提交于 2019-12-21 03:56:15

问题


The last option to solve this for me was to ask StackOverflow.

I am trying to create a Solr query to get documents that have a specific value on one of its fields OR that does not have a value...

Theorically, this query should have worked.

Here is some information:

Query: (name: john) --> Result count: 15383 //Johns

Query: (name: {* TO *}) --> Result count: 61013 //People that have a name

Query: -(name: {* TO *}) --> Result count: 216888 //People that do not have a name

Now, when I use first and third query in a same query with OR operator, I expect to get (216888 + 15383) results. But SOLR gives 15383 results, simply ignores the effect of third query:

Query: +((name:john) (-(name:{* TO *}))) //This is the query I was used.

Is this a bug of Solr or am I doing wrong in query? Merging two query results is an additional solution but I do not want to do extra code implementation if I could do it with a simple query.

Any help would be appreciated.


回答1:


(-name:[* TO *] AND *:*) OR name:john




回答2:


You can also use it like this.

&fq=name:john OR !name:['' TO *]



回答3:


try the below query -

q=(name:john OR -(name:[* TO *]))


来源:https://stackoverflow.com/questions/7672259/how-to-or-null-value-in-apache-solr-query

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