vashishth
vashishth

Reputation: 3400

solr search query with boolean parameter

The following is the document I indexed into solr:

    <doc>
        <field name="definition">Bookshelf are to keep books. </field>
        <field name="whword">what</field>
        <field name="definitionKey">bookshelf</field>
    </doc>

Now I need to query this document. But my requirement is to check if both definitionkey and whword values are equals. The following is the query:

http://localhost:8983/solr/faqcore/select?q=definitionKey:bookself&whword=null&wt=json

Now in this query, the value of whword is null and this is not equal to the value in document. In this case the result should be null, but I am still getting the whole document as json in my output.

Please provide your suggestion.

Upvotes: 0

Views: 829

Answers (1)

Jozef Chocholacek
Jozef Chocholacek

Reputation: 2924

First, you cannot add whword=null as a request parameter, it has to be part of either query (q) or filter query (fq).

Then, Solr does not know null value. You have to specify a "negative" condition, either in query or in filter query. Condition to get documents with not empty whword is whword:[* TO *] (mind the uppercase TO!), so any of the following should work (I skip &wt=json at the end of each variant):

  1. q=definitionKey:bookshelf+-whword:[*+TO+*]
  2. q=definitionKey:bookshelf+AND+NOT+whword:[*+TO+*]
  3. q=definitionKey:bookshelf&fq=-whword:[*+TO+*]

Upvotes: 2

Related Questions