I am having a list of profiles in solr, indexing with some empty fields (e.g.: country/category etc).

<arr name="country">
    <str>185</str>
</arr>
<arr name="category">
    <int>38</int>
</arr>

I want to search profiles with no country. I used -country:['' TO *] as country is a string field.

Now how can I check it for an integer field? The field may be empty (no field) or with value 0. I tried category:0 but it is not giving me the correct output, output is empty in this case.

有帮助吗?

解决方案

For string type of field you could query like

-country:* OR country:""

It'll give you all the Solr document which doesn't have country field at all. Or country with empty string.

For integer type field

-category:* OR category:0

It'll give you result with empty(no field) or with value 0.

There is an issue with Solr OR and NOT search. Please refer to using OR and NOT in solr query for a better understanding of OR and NOT query.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top