Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Quick reference for solr

Cheat Sheet for Solr

  • Login to see the comments

  • Be the first to like this

Quick reference for solr

  1. 1. To start solr ============= C:Program Filessolr-5.4.0bin> solr start -f C:Program Filessolr-5.4.0bin> solr start -f -p 8983 Note: start the service as a foreground process using -f, otherwise restart will not work with background process -------------------------------------------------------------------------------- ------------------------------------------------------ To stop solr ============ C:Program Filessolr-5.4.0bin> solr stop -f -p 8983 C:Program Filessolr-5.4.0bin> solr stop -f -all -------------------------------------------------------------------------------- ------------------------------------------------------ To restart solr =============== C:Program Filessolr-5.4.0bin> solr restart -f -p 8983 -------------------------------------------------------------------------------- ------------------------------------------------------ To validate solr ================ http://localhost:8983/solr/ ******************************************************************************** ****************************************************** Configuration ******************************************************************************** ****************************************************** Creating a Core =============== C:Program Filessolr-5.4.0bin> solr create -c csvcore -d basic_configs -p 8983 C:Program Filessolr-5.4.0bin> solr create -c jsoncore -d basic_configs -p 8983 C:Program Filessolr-5.4.0bin> solr create -c xmlcore -d basic_configs -p 8983 Deleting a Core =============== C:Program Filessolr-5.4.0bin> solr delete -c csvcore -p 8983 C:Program Filessolr-5.4.0bin> solr delete -c jsoncore -p 8983 C:Program Filessolr-5.4.0bin> solr delete -c xmlcore -p 8983 Explanation ----------- -c <name> - Name of the core or collection to create (required). -d <confdir> - The configuration directory, useful in the SolrCloud mode. -n <configName> - The configuration name. This defaults to the same name as the core or collection. -p <port> - Port of a local Solr instance to send the create command to; by default the script tries to detect the port by looking for running Solr instances. -s <shards> - Number of shards to split a collection into, default is 1. -rf <replicas> - Number of copies of each document in the collection. The default is 1. -------------------------------------------------------------------------------- ------------------------------------------------------ Modify the schema.xml file ========================== For CSV data - C:Program Filessolr-5.4.0serversolrcsvcoreconfschema.xml ------------ <uniqueKey>id</uniqueKey> <!-- Fields added for books.csv load--> <field name="cat" type="text_general" indexed="true"
  2. 2. stored="true"/> <field name="name" type="text_general" indexed="true" stored="true"/> <field name="price" type="tdouble" indexed="true" stored="true"/> <field name="inStock" type="boolean" indexed="true" stored="true"/> <field name="author" type="text_general" indexed="true" stored="true"/> For JSON data - C:Program Filessolr-5.4.0serversolrjsoncoreconfschema.xml ------------- <uniqueKey>id</uniqueKey> <!-- Added for Multi value example --> <field name="name" type="text_general" indexed="true" stored="true"/> <field name="cat" type="text_general" indexed="true" stored="true" multiValued="true"/> <field name="price" type="tdouble" indexed="true" stored="true"/> <field name="inStock" type="boolean" indexed="true" stored="true"/> <field name="author" type="text_general" indexed="true" stored="true"/> For XML data ------------ Since the default data format is xml, schema definition is not necessary Explanation ----------- name: Name of the field required type: Field type required indexed: Should this field be added to the inverted index? optional stored: Should the original value of this field be stored? optional multiValued: Can this field have multiple values? optional Restart solr to reflect the changes ----------------------------------- C:Program Filessolr-5.4.0bin> solr restart -f -p 8983 -------------------------------------------------------------------------------- ------------------------------------------------------ Indexing the Data ================= C:Program Filessolr-5.4.0exampleexampledocs> java -Dtype=text/csv -Durl=http://localhost:8983/solr/csvcore/update -jar post.jar books.csv C:Program Filessolr-5.4.0exampleexampledocs> java -Dtype=text/json -Durl=http://localhost:8983/solr/jsoncore/update -jar post.jar books.json C:Program Filessolr-5.4.0exampleexampledocs> java -Dtype=text/xml -Durl=http://localhost:8983/solr/xmlcore/update -jar post.jar *.xml Explanation ----------- -Dtype -> the type of the data file. JSON file: text/json, application/json XML files: text/xml, application/xml CSV file: text/csv, application/csv -Durl -> URL for the core. ******************************************************************************** ****************************************************** Access the Indexed documents ********************************************************************************
  3. 3. ****************************************************** C:Program Filessolr-5.4.0bin> solr -e techproducts -f -p 8983 Querying Data ============= http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&fl=name,id http://localhost:8983/solr/#/techproducts/query? indent=on&q=video&fl=name,id,score http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&fl=*,score http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=price desc&fl=name,id,price http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&wt=json -------------------------------------------------------------------------------- ------------------------------------------------------ Sorting ======= http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=price desc http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=price asc http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=inStock asc, price desc http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=score desc http://localhost:8983/solr/#/techproducts/query?indent=on&q=video&sort=inStock asc, score desc http://localhost:8983/solr/#/techproducts/query? indent=on&q=video&sort=div(popularity,add(price,1)) desc -------------------------------------------------------------------------------- ------------------------------------------------------ Highlighting ============ http://localhost:8983/solr/#/techproducts/query? indent=on&q=video+card&fl=name,id&hl=true&hl.fl=name,features -------------------------------------------------------------------------------- ------------------------------------------------------ Faceted Search ============== http://localhost:8983/solr/#/techproducts/query? indent=on&q=*:*&fl=name&facet=true&facet.field=cat http://localhost:8983/solr/#/techproducts/query? indent=on&q=*:*&fl=name&facet=true&facet.field=cat&facet.field=inStock http://localhost:8983/solr/#/techproducts/query? indent=on&q=ipod&fl=name&facet=true&facet.query=price: [0+TO+100]&facet.query=price:[100+TO+*] http://localhost:8983/solr/#/techproducts/query? indent=on&q=*:*&fl=name,manufacturedate_dt&facet=true&facet.date=manufacturedate _dt&facet.date.start=2004-01-01T00:00:00Z&facet.date.end=2010-01- 01T00:00:00Z&facet.date.gap=%2b1YEAR

×