Anurag Sharma
Anurag Sharma

Reputation: 5049

order documents with a particular field first in solr

I have a solr field namely 'crs_name' which is a multivalued field in solr. But its not present in all the documents.

When I perform a query below

http://127.0.0.1:8983/solr/institute/select?=*:*&fl=crs_name&wt=json&indent=true

I will get response like this

response":{"numFound":781,"start":0,"docs":[
      {},
      {},
      {},
      {
        "crs_name":["MBA",
        "B.Tech",]
      },
      {},
      {},
      {},
      {},
      {},
      {}]

Is it possible to display those document first which have the 'crs_name' field in them, for eg --

response":{"numFound":781,"start":0,"docs":[
      {
        "crs_name":["MBA",
        "B.Tech",]
      },
      {
        "crs_name":["B.Tech",]
      },
      {
        "crs_name":["MBA",]
      },
      {},
      {},
      {},
      {},
      {},
      {}]

Upvotes: 0

Views: 39

Answers (1)

Mysterion
Mysterion

Reputation: 9320

You need to update your schema.xml, so your crs_name field type will have this param - sortMissingLast=true.

It should help you. For more info take a look here - http://wiki.apache.org/solr/SchemaXml#Data_Types

Upvotes: 1

Related Questions