Setup New Core Collection

SOLR is up and running now, you may want to setup a new core collection. Creating a new core is similar to “create database” in traditional database. We will use the bundled example “films” to demonstrate how to set it up. Let’s try to create a new one now:

 

  1. Make sure your SOLR is running now, you can start it up by “solr start” under the command prompt.

  1. Enter “solr create –c films”

  1. Add 2 fields (name and initial_release_date) to this collection by either:

a. Running curl http://localhost:8983/solr/films/schema -X POST -H ‘Content-type:application/json’ –data-binary ‘{

    “add-field” : {

        “name”:”name”,

        “type”:”text_general”,

        “stored”:true

    },

    “add-field” : {

        “name”:”initial_release_date”,

        “type”:”tdate”,

        “stored”:true

    }

}’

b. Using Postman to make HTTP POST request, you can download it from https://www.getpostman.com/ . After installed Postman, please:

{

    “add-field” : {

        “name”:”name”,

        “type”:”text_general”,

        “stored”:true

    },

    “add-field” : {

        “name”:”initial_release_date”,

        “type”:”tdate”,

        “stored”:true

    }

}

  • Press “Send”

 

  1. Import some articles into films collection by either:

a. bin/post -c films example/films/films.json

b. bin/post -c films example/films/films.xml

c. bin/post -c films example/films/films.csv -params “f.genre.split=true&f.directed_by.split=true&f.genre.separator=|&f.directed_by.separator=|”

d. Or, open C:/{your_installed_path}/solr-5.4.1/example/films/films.csv with editor, copy the records and paste to Document(s) of the page : http://localhost:8983/solr/#/films/documents , and select “CSV” for Document Type, press “Submit Document” to submit. Please note that you can submit with other file format such as JSON or XML.

 

It will return update status as:

 

  1. Try querying with http://localhost:8983/solr/films/query?q=*:* , it will return you list of records (by default 10 rows)

 

  1. You can also go to http://localhost:8983/solr/films/browse , it will show you a simple collection browsing page:

 

  1. If you want to set a facet field, e.g. genre, you can do so by:

a. curl http://localhost:8983/solr/films/config/params -H ‘Content-type:application/json’ -d ‘{

“update” : {

“facets”: {

“facet.field”:”genre”

}

}

}’

b. or, using Postman to make a HTTP POST request, please:

{

“update” : {

“facets”: {

“facet.field”:”genre”

}

}

}

  • Press “Send”

 

c. Let’s browse the http://localhost:8983/solr/films/browse again, you will find facet field on the left:

 

  1. If you want to high light the searching key like:

 

You can either:

a. curl http://localhost:8983/solr/films/config/params -H ‘Content-type:application/json’ -d ‘{

“set” : {

“browse”: {

“hl”:”on”,

“hl.fl”:”name”

}

}

}’

b. or, using Postman to make a HTTP POST request, please:

{

“set” : {

“browse”: {

“hl”:”on”,

“hl.fl”:”name”

}

}

}

  • Press “Send”

 

  1. You can also go to http://localhost:8983/solr/#/films/query to query the article(s).

 

You see, it’s so simple to setup and configure SOLR. Let’s have some funs with it.

Please rate this