SOLR Query similarto NOT IN (LIST) - solr

I have a requirement where we need to fetch the values like
CustomerID NOT IN (LIST OF IDs Indexed) from SOLR Index.
Can anyone suggest how can we achieve this using solr query?.

Use Filter query fq=-id:("id1", id:"id2")
example
http://localhost:8983/solr/collection/select?indent=on&q=querystring&wt=json&fq=-id:("id1", id:"id2")
Here it discards documents with list of IDs mentioned in filter query(fq) parameter

CustomerID:* AND NOT CustomerID:(ID1 OR ID2 OR ... IDn)

Related

How to search multiple words in one field on solr?

I have a field in solr of type list of texts.
field1:{"key1:val1,key2:val2,key3:val3", "key1:val1,key2:val2"}
I want to form a query such that when I search for key1:val1 and key3:val3 I get the result who has both the strings i.e key1:val1 and key3:val3.
How shall I form the query?
If these are values in a multivalued field, you can't - directly. You'll have to use something like highlighting to tell you where Solr matched it.
There is no way to tell Solr "I only want the value that matched inside this set of values".
If this is a necessary way to query your index, index the values as separate documents instead in a separate collection. In that case you'd have to documents instead, one with field1:"key1:val1,key2:val2,key3:val3" and one with key1:val1,key2:val2.
You can use AND with fq.
Like:
fq=key1:val1 AND key3:val3
With this filter query you will get only records where key1 = val1 AND key3 = val3.

Solr Exclude Filter for Category

Using Solr 6, for e-commerce catalog with search and filtering.
I need to exclude all products for certain category? Not sure how to do that in Solr. Can you give some idea, how can we achieve that?
Note that, CategoryID is a multi valued string field, as one product can be assigned to multiple categories.
Use the boolean "NOT" operator.
* NOT CategoryID:111
Alternative syntax :
* -CategoryID:111
* !CategoryID:111
Documentation : https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-BooleanOperatorsSupportedbytheStandardQueryParser

How can I use Solr subquery similar to rdbms subqueries?

I need to run a query in Solr that contains another query as terms of the main query!
Something like this in the RDBMS SQL:
select name from movie
where movie.writer in (
select director from movie where producer = 'XXX'
)
Is there any way to do this is Solr?
Solved.
This is possible using "join" in Solr.
Following is the solution for my answered example:
fl=name&
q={!join from=writer to=director}+producer:XXX
Also a filter query can be added. This filter will affect the result of join and query.
Thanks to Ramzy.
you can try filter, something like this..
q=movie:name
fq=(writer:writer_name AND producer:Producer_name)
also the data that you put into a Solr index is flat or denormalized.
So take the suquery field values and put them in an AND part of the query to Solr.
q=(movie:name AND writer:Writer_name AND producer:Producer_name)

Difference between q and fq in Solr

Someone please give me a decent explanation of the difference between q and fq in Solr query, covering some points such as -
Do they have the same syntax?
Do they return same results?
When to use which one and why?
Any other differences
Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter.
The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).
The q parameter takes your query and execute against the index. Then you can use filter queries (can use multiple filter queries) to filter the results.
For example your query can look like this.
q=author:shakespeare
this will match the documents which has 'shakespeare' in the 'author' field. Then you can use filter queries like this.
fq=title:hamlet
fq=type:play
Those will filter the results based on the other fields. You can even filter on the same field.
The query syntax is similar for both q and fq parameters

solr query without order

I have a solr index with the unique field as "id".
I have a ordered set of ids, using which I would like to query Solr. But I want the results in the same order.
so for example if i have the ids id = [5,1,3,4] I want the results displayed in solr in same order.
I tried http://localhost:8983/solr/select/?q=id:(5 OR 1 OR 3 OR 4)&fl=id, but the results displayed are in ascending order.
Is their a way to query solr, and get results as I mentioned?
I think you can't,
The results appear in the order they are indexed unless you specify a default sort field or the explicit sort field/order.
You can add another field to keep the initial sort order. You then can sort=field asc to retrieve the data in the original order.
The simple way is to query solr and sort the results in codes of yourself.

Resources