Warm tip: This article is reproduced from stackoverflow.com, please click
lucene solr

Looking for solr query which will include results with both missing field and the same field which h

发布于 2020-05-02 09:48:24

Let's say I have the following data

{
 fruit: "Mango",
 cost : 2.00,
 variety : "alphanso",
},
{
 fruit : "apple",
 cost : 1.40,
 variety : "Gala"
},
{
 fruit : "apple",
 variety : "cosmic crisp",
},
{
fruit : "apple",
variety : "honey crisp",
cost : 2.99
}

I am looking for a search that returns apples with a cost between 1 and 2 and also returns the variety that doesn't have a cost field set.

In this case, the result will contain "Gala" and "cosmic crisp"

Questioner
user2938885
Viewed
69
MatsLindh 2020-02-13 17:00

Start with the complete set of documents, *:*, subtract those that have a value [* TO *], and add those that match variety:Gala.

q=(*:* -cost:[* TO *]) OR variety:Gala