elier
elier

Reputation: 459

Bad request from solr by just changing the order in the filter query

The following solr request works just fine:

&json.facet={domains:{type:terms,field:domains,domain:{excludeTags:DOMAIN}},specialties:{type:terms,field:specialties,domain:{excludeTags:SPECIALTY}}}
&fq={!tag=SPECIALTY}specialties:(1043 1023) AND {!tag=DOMAIN}domains:100

If I just change the order in the fq parameter, solr response with 400 Bad Request.

&json.facet={domains:{type:terms,field:domains,domain:{excludeTags:DOMAIN}},specialties:{type:terms,field:specialties,domain:{excludeTags:SPECIALTY}}}
&fq={!tag=DOMAIN}domains:100 AND {!tag=SPECIALTY}specialties:(1043 1023)

I would like to know if I'm doing something wrong or it if could be a problem in solr.

I'm using solr 7.2.1 and I'm following thes tutorial from Yonik:
http://yonik.com/multi-select-faceting/

Upvotes: 1

Views: 188

Answers (2)

elier
elier

Reputation: 459

This is very weird. A colleague found that by adding an space between the tag and the field the query works as expected in any order. Also, adding the plus sign force to match all conditions. Here is the working query, just adding space and plus sign in fq parameter:

&json.facet={domains:{type:terms,field:domains,domain:{excludeTags:DOMAIN}},specialties:{type:terms,field:specialties,domain:{excludeTags:SPECIALTY}}}
&fq={!tag=DOMAIN} +domains:100 AND {!tag=SPECIALTY} +specialties:(1043 1023)

Use this with caution. This might be a hack. The documentation is not clear about this.

Upvotes: 1

MatsLindh
MatsLindh

Reputation: 52792

A localparam (i.e. the thing between {}) has to be the first thing in a parameter. The second localparam you've added in the middle of your filterquery isn't being used as you expect it to, but when you move it to the front, it's suddenly being parsed.

You should split the two parts into separate fqs:

&fq={!tag=DOMAIN}domains:100
&fq={!tag=SPECIALTY}specialties:(1043 1023)

If you still get a Bad Request 400 - check the actual server log in your Solr instance - it'll show you what part it's barfing about (misspelling, etc.).

Upvotes: 2

Related Questions