Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not query in lucene

Tags:

i need to do not queries on my lucene index. Lucene currently allows not only when we have two or more terms in the query:

So I can do something like:

country:canada not sweden

but I can't run a query like:

country:not sweden

Could you please let me know if there is some efficient solution for this problem

Thanks

like image 219
Ted Rogati Avatar asked Aug 30 '10 22:08

Ted Rogati


People also ask

How do you use not in Lucene query?

The short answer is that this is not possible using the standard Lucene. Lucene does not allow NOT queries as a single term for the same reason it does not allow prefix queries - to perform either, the engine would have to look through each document to ascertain whether the document is/is not a hit.

How do you search in Lucene?

Lucene supports fielded data. When performing a search you can either specify a field, or use the default field. The field names and default field is implementation specific. You can search any field by typing the field name followed by a colon ":" and then the term you are looking for.

How do you use Lucene query syntax in Kibana?

To use the Lucene syntax, open the Saved query menu, and then select Language: KQL > Lucene. To search for a range of values, use the bracketed range syntax, [START_VALUE TO END_VALUE] . For example, to find entries that have 4xx status codes, you could enter status:[400 TO 499] .

Does Google use Lucene?

Despite these open-source bona fides, it's still surprising to see someone at Google adopting Solr, an open-source search server based on Apache Lucene, for its All for Good site. Google is the world's search market leader by a very long stretch.


2 Answers

A very late reply, but it might be useful for somebody else later:

*:* AND NOT country:sweden

IF I'm not mistaken this should do a logical "AND" with all documents and the documents with a country that is different from "sweden".

like image 197
Jan Goyvaerts Avatar answered Sep 17 '22 06:09

Jan Goyvaerts


Try with the following query in the search box:

NOT message:"warning"

message being the search field

like image 43
Heena Hussain Avatar answered Sep 21 '22 06:09

Heena Hussain