cd solr-6.6.0\
bin\solr start -e cloud -noprompt
D:\machine\solr\solr-6.6.0>bin\solr start -e cloud -noprompt Welcome to the SolrCloud example! Starting up 2 Solr nodes for your example SolrCloud cluster. ... Started Solr server on port 8983. Happy searching! ... Started Solr server on port 7574. Happy searching! ... SolrCloud example running, please visit: http://localhost:8983/solr D:\machine\solr\solr-6.6.0>
Solr 如今将运行两个节点,一个在端口7574,一个在端口8983,有一个自动建立的文档
gettingstarted
,默认有两个分片收集,每一个分片有两个副本,这管理页面的Cloud tab 能够很直观的查看。html
Solr服务器已经启动并运行,可是它不包含任何数据。Solr安装包括了bin/post工具,以便从一开始就方便地从Solr的文档中得到各类类型的文档。java
在windows中,bin/post能够委托给一个独立运行的Java程序叫
SimplePostTool
,能够执行运行java -jar example/exampledocs/post.jar
node
D:\machine\solr\solr-6.6.0>java -jar example\exampledocs\post.jar -h
查看帮助能够(获取文件,递归到一个网站或文件系统文件夹,或者向Solr服务器发送直接命令) SimplePostTool version 5.0.0 Usage: java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]] ... ...
重点在这里:java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]]
linux
|
表示或者,SystemProperties
表示系统属性;这里的
key,value
值都是随便定义的,没什么特别要求,这样你随后经过System.getProperty(key)
经过key就能在任意时刻获取到该key对应的参数值,若是是在dos命令行下,你也能够经过java -Dkey=value这种方式指定,至此java [SystemProperties]
这部分你应该理解了,至于后面的-jar
是java命令的参数,即执行一个jar文件,-jar后面指定一个jar包路径,默认是相对于当前所在路径,-h
即表示添加了这个即会打印命令提示信息,就比如你敲java -h是相似的,后面的file,folder,url,args分别表示你要提交的数据的几种不一样表示形式,file即表示你要提交的数据是存在于文件中,而folder即表示你要提交的存在于文件夹中,url即表示你要提交的数据是存在于互联网上的一个URL地址表示的资源,它多是一个HTML页面,多是一个PDF文件,多是一个图片等等,args即表示你要提交的数据直接在命令行敲出来,但arges并非随随便便一个字符串就行的,它须要有固定的格式,solr才能解析web
java -jar example\exampledocs\post.jar -h
查看帮助列出的内容说到:Supported System Properties and their defaults: -Dc=<core/collection> -Durl=<base Solr update URL> (overrides -Dc option if specified) -Ddata=files|web|args|stdin (default=files) -Dtype=<content-type> (default=application/xml) -Dhost=<host> (default: localhost) -Dport=<port> (default: 8983) -Dbasicauth=<user:pass> (sets Basic Authentication credentials) -Dauto=yes|no (default=no) -Drecursive=yes|no|<depth> (default=0) -Ddelay=<seconds> (default=0 for files, 10 for web) -Dfiletypes=<type>[,<type>,...] (default=xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log) -Dparams="<key>=<value>[&<key>=<value>...]" (values must be URL-encoded) -Dcommit=yes|no (default=yes) -Doptimize=yes|no (default=no) -Dout=yes|no (default=no)
-D
是命令行下指定系统属性的固定前缀数据库
http://host:port/solr/${collectionName}/update
,这里的${collectionName}
和上面的c属性值保持一致data表示你要提交数据的几种模式,files模式表示你要提交的数据在文件里apache
dos
命令行下经过System.in
输入流临时接收,跟args
有点相似,但不一样的是,stdin
模式下,post.jar后面不须要指定任何参数,直接回车便可,而后程序会等待用户输入,用户输入完毕再回车,post.jar
会接收到用户输入,post.jar
从新被唤醒继续执行。而args
是直接在post.jar
后面输入参数,没有一个中断过程,而stdin
模式下若是用户一直没有输入,那post.jar
就会一直阻塞在那里等待用户输入为止。post.jar
支持提交哪些文件类型,后面有列出默认支持的文件类型,若是你想覆盖默认值,那么请指定此参数id=1&name=yida
之类的false
表示不提交至sor admin,但设置为true
也不必定就意味着就必定会把索引写入磁盘,这取决于solrconfig
中directory
配置的实现是什么,若是配置的是RAMDirectory
,就仅仅只在内存中操做了。no
即表示不对索引进行优化Examples: java -Dc=gettingstarted -jar post.jar *.xml java -Ddata=args -Dc=gettingstarted -jar post.jar '<delete><id>42</id></delete>' java -Ddata=stdin -Dc=gettingstarted -jar post.jar < hd.xml java -Ddata=web -Dc=gettingstarted -jar post.jar http://example.com/ java -Dtype=text/csv -Dc=gettingstarted -jar post.jar *.csv java -Dtype=application/json -Dc=gettingstarted -jar post.jar *.json java -Durl=http://localhost:8983/solr/techproducts/update/extract -Dparams=literal.id=pdf1 -jar post.jar solr-word.pdf java -Dauto -Dc=gettingstarted -jar post.jar * java -Dauto -Dc=gettingstarted -Drecursive -jar post.jar afolder java -Dauto -Dc=gettingstarted -Dfiletypes=ppt,html -jar post.jar afolder
Solr安装后,包括一个docs/
子目录,windows下使用以下命令:java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar docs/
编程
linux下可使用bin/post -c gettingstarted docs/
命令解析:json
-c gettingstarted
:要索引的集合的名称docs/
: Solr安装目录下的/docs
的相对路径使用bin/post
,索引示例Solr XML文件中的示例/example
文档/:
linux下使用:bin/post -c gettingstarted example/exampledocs/*.xml
windows下使用:java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\*.xml
你将会看到:windows
D:\machine\solr\solr-6.6.0>java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\*.xml SimplePostTool version 5.0.0 Posting files to [base] url http://localhost:8983/solr/gettingstarted/update... Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log Entering recursive mode, max depth=999, delay=0s POSTing file gb18030-example.xml (application/xml) to [base] POSTing file hd.xml (application/xml) to [base] POSTing file ipod_other.xml (application/xml) to [base] POSTing file ipod_video.xml (application/xml) to [base] POSTing file manufacturers.xml (application/xml) to [base] POSTing file mem.xml (application/xml) to [base] POSTing file money.xml (application/xml) to [base] POSTing file monitor.xml (application/xml) to [base] POSTing file monitor2.xml (application/xml) to [base] POSTing file mp500.xml (application/xml) to [base] POSTing file sd500.xml (application/xml) to [base] POSTing file solr.xml (application/xml) to [base] POSTing file utf8-example.xml (application/xml) to [base] POSTing file vidcard.xml (application/xml) to [base] 14 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update... Time spent: 0:00:03.233
注意:您能够浏览文档索引在http://localhost:8983/solr/ge...
linux使用: bin/post -c gettingstarted example/exampledocs/books.json
windows使用:java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\books.json
你将看到以下信息:
D:\machine\solr\solr-6.6.0>java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\books.json SimplePostTool version 5.0.0 Posting files to [base] url http://localhost:8983/solr/gettingstarted/update... Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log Entering recursive mode, max depth=999, delay=0s POSTing file books.json (application/json) to [base]/json/docs 1 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update... Time spent: 0:00:01.211
linux下使用:bin/post -c gettingstarted example/exampledocs/books.csv
windows下使用:java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\books.csv
在你的终端,你会看到:
D:\machine\solr\solr-6.6.0>java -Dc=gettingstarted -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar example\exampledocs\books.csv SimplePostTool version 5.0.0 Posting files to [base] url http://localhost:8983/solr/gettingstarted/update... Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log Entering recursive mode, max depth=999, delay=0s POSTing file books.csv (text/csv) to [base] 1 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update... Time spent: 0:00:00.874
更多信息,请参阅Solr指南部分CSV格式的索引更新CSV Formatted Index Updates
Document Type
的下拉选项卡选择Document Builder
每次添加一个字段来构建文档.单击表单下面的Submit文档按钮,以索引文档。schema.xml
指定了一个uniqueKey
字段id
,即便咱们索引一个内容屡次,它也不会重复添加,当咱们POST命令到Solr添加文档时,若是uniqueKey
字段当前值已存在,它会自动替换原来的内容.linux使用:bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"
windows使用:java -Dc=gettingstarted -Ddata=args -jar example\exampledocs\post.jar "<delete><id>1</id></delete>"
Solr能够经过REST客户端,cURL,wget,POSTMAN等来查询,以及许多编程语言均可以使用的本地客户端。
gettingstarted
默认文档查询:http://localhost:8983/solr/#/...若是你不改变表单里的任何内容,直接点击Execute Query
按钮,你将获得默认10条JSON格式的文档(*:*
做为q的参数表示匹配全部文档)由Admin UI发送到Solr的URL显示在上面屏幕右上角的浅灰色中,若是你点击它,你的浏览器将会显示原始的响应。要使用cURL,请在cURL命令行中使用相同的URL:
curl "http://localhost:8983/solr/gettingstarted/select?indent=on&q=*:*&wt=json"
搜索一个特定的词,须要把在Solr Admin UI查询板块中的
q
的参数值*:*
替换成你想要查询的词
curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation"
你将获得:
$ curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2017 100 2017 0 0 123k 0 --:--:-- --:--:-- --:--:-- 123k{ "responseHeader":{ "zkConnected":true, "status":0, "QTime":17, "params":{ "q":"foundation", "indent":"true", "wt":"json"}}, "response":{"numFound":3,"start":0,"maxScore":3.4038174,"docs":[ { "id":"0553293354", "cat":["book"], "name":["Foundation"], "price":[7.99], "inStock":[true], "author":["Isaac Asimov"], "series_t":["Foundation Novels"], "sequence_i":1, "genre_s":"scifi", "_version_":1576664844219711488}, { ...
响应代表,有3个命中("numFound":3),其中前10个被返回,由于默认的start=0
,rows=10
。您能够经过指定这些params查询结果,其中start
是第一个结果返回的(基于零的)位置,而raws
是一页的大小。
fl param
,该命令将使用逗号分隔的字段名列表。只返回id
字段:curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation&fl=id"
q=foundation
匹配了咱们已经索引的几乎全部文档,由于文档中的大多数文件都包含“Apache软件基金会”。要限制搜索到特定字段,使用语法"q=field:value",例如只在name字段中搜索Foundation:curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=name:Foundation"
要搜索一个多词短语,用双引号括起来:
q="这里的多个词语"
。例如,搜索"CAS latency"注意,术语之间的空格必须转换为"+"
(Admin UI将自动处理URL编码):
curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=\"CAS+latency\""
你将看到:
"responseHeader":{ "zkConnected":true, "status":0, "QTime":9, "params":{ "q":"\"CAS latency\"", "indent":"true", "wt":"json"}}, "response":{"numFound":2,"start":0,"maxScore":2.9027793,"docs":[ { "id":"TWINX2048-3200PRO", "name":["CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail"], "manu":["Corsair Microsystems Inc."], "manu_id_s":"corsair", "cat":["electronics", "memory"], "features":["CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader"], ...
默认状况下,当你在单一查询中搜索多个词或短语时,Solr只要求其中一个匹配,以便让文件匹配,包含更多词语的文档将在结果列表中排序更高。
curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=on&q=%2Baaa+%2BFoundatio"
"Foundation"
可是不含有"aaa"
的文档,在Admin UI 的查找页面的q
参数中输入+Foundation -one
,在curl中将"+"
编码为"%2B"
$ curl "http://localhost:8983/solr/gettingstarted/select?wt=json&indent=on&q=%2BFoundation+-aaa"
深刻学习:要了解更多Solr搜索选项,请参阅Solr参考指南的搜索部分。
bin/solr stop -all ; rm -Rf example/cloud/