玩转Apache Solr 6.5.1

以下都是基于linux环境
参考链接:http://lucene.apache.org/solr/quickstart.html

目录:
  1. solr 基本命令总结
  2. solr 命令参数详解
  3. solr 查询语法详解
  4. solr schema配置详解

1. solr基本命令总结:


进入solr解压后的文件夹

cd solr-6.5.1/

启动solr service在8080端口

bin/solr start -p 8080(端口号) 

停止所有solr service

bin/solr stop -all     

重新启动solr service在8080端口

bin/solr restart -p 8080      

启动solrcloud示例cloud;对应的core示例是gettingstarted

bin/solr start -e cloud        

启动solr示例techproducts;对应的core示例是techproducts

bin/solr start -e techproducts    

启动solr的Web页面

open http://localhost:8080/solr       

创建一个core

bin/solr create -c core0(core的名字)

solr索引结构化内容 示例结构化文件路径example/exampledocs

bin/post -c core0(自己的core的名字)   docs/*.xml(需要索引的文件路径或父文件夹,文件格式可以是xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods)

打开索引搜索模式的Web界面。这是一个示例链接,端口号和core名字要写自己的

open localhost:8080/solr/core0/browse       

删除id=SP2514N的文件

bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"   

2. solr命令参数详解:


solr start [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-a "additional-options"] [-V]

-f
设置前台启动solr,并将标准输出或错误信息发送到solr-PORT-console.log; solr默认是在后台启动的

   -f:   Start Solr in foreground; default starts Solr in the background 
  and sends stdout/stderr to solr-PORT-console.log

-c or -cloud
在SolrCloud模式下启动Solr;如果没有指定-z,zookeeper将在port+1000的端口启动

  -c or -cloud:    Start Solr in SolrCloud mode; if -z not supplied, an embedded Zookeeper
  instance is started on Solr port+1000, such as 9983 if Solr is bound to 8983

-h <host>
指定solr实例的主机名

-h <host>:    Specify the hostname for this Solr instance

-p <port>
指定启动solr http 侦听器的端口,默认值为8983。指定的端口也用于停止/重启solr服务以及进行其他的solr操作。

 -p <port>:    Specify the port to start the Solr HTTP listener on; default is 8983
 The specified port (SOLR_PORT) will also be used to determine the stop port
 STOP_PORT=($SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=($SOLR_PORT+10000). 
  For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985

-d <dir>
指定solr服务器目录,默认为服务器

-d <dir>:  Specify the Solr server directory; defaults to server

-z <zkHost>
zookeeper连接字符串;仅在-c/-cloud模式下使用。

-z <zkHost>:    Zookeeper connection string; only used when running in SolrCloud mode using -c
    To launch an embedded Zookeeper instance, don't pass this parameter.

-m <memory>
设置 jvm 的最小 (-xms) 和最大 (--xmx) 堆大小

-m <memory>:    Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g
    results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m

-s <dir>
设置solr.solr.home系统属性。将在这个目录创建核心目录。这使您可以在统一主机运行多个solr实例。默认自带目录/solr

-s <dir>:     Sets the solr.solr.home system property; Solr will create core directories under
 this directory. This allows you to run multiple Solr instances on the same host
 while reusing the same server directory set using the -d parameter. If set, the
 specified directory should contain a solr.xml file, unless solr.xml exists in Zookeeper.
 This parameter is ignored when running examples (-e), as the solr.solr.home depends
 on which example is run. The default value is server/solr.

-e <example>
要运行的实例的名称可以使用自带示例techproducts

 -e <example>:  Name of the example to run; available examples:
  cloud:         SolrCloud example
  techproducts:  Comprehensive example illustrating many of Solr's core capabilities
  dih:           Data Import Handler
  schemaless:    Schema-less example

-a
启动时传给jvm的附加参数

 -a:       Additional parameters to pass to the JVM when starting Solr, such as to setup
    Java debug options. For example, to enable a Java debugger to attach to the Solr JVM
     you could pass: -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983"
    In most cases, you should wrap the additional parameters in double quotes.

- noprompt
不提示输入;在运行接受用户输入的示例时接受所有默认值

 -noprompt: Don't prompt for input; accept all defaults when running examples that accept user input

-v and -q
使用调试或一般记录。将默认日志级别设置为 "调试" 或 "警告" 而不是 "信息"

 -v and -q:Verbose (-v) or quiet (-q) logging. Sets default log level to DEBUG or WARN instead of INFO
  -V or -verbose Verbose messages from this script

3. solr 查询语法详解

支持的参数
  • q
    主查询参数
    写法:q=<field_name>:<value>field_name可省略
    样例:q=*:*(返回全部);q=西夏q=name:西夏*q=(博物馆 OR type_i:0)
  • sort
    按照升序或降序对查询的响应进行排序
    可选参数:asc(倒序),desc(正序,默认值)【不区分大小写】
    写法:sort=<field name>+<direction>,<field name>+<direction>],...
    样例:sort=id ascsort=updated_at_d+descsort=log_id asc ,start_time desc
  • start
    起始数据偏移量,用于分页(默认值:0)
    样例:start=0
  • rows
    控制一次返回的数据量,用于分页(默认值:10)
    样例:rows=20
  • fq [filter query]
    返回搜索结果的过滤器查询
    写法:fq=<field_name>:<value>
    样例:fq=net_type:1fq=net_type:1 AND (idt_id:12011 OR idt_id:5004) AND time_type:1fq=net_type:1&fq=idt_id:12011
  • fl [fields to list]
    限制查询响应中返回的指定字段列表。
    写法:fl=<field_name>,<field_name>fl=<field_name>+<field_name>
    样例:fl=*+namefl=log_id,start_time,end_time
  • wt (response writer)
    指定用于格式化查询响应的响应写入器格式。
    样例:wt=rubywt=xmlwt=json
  • timeallowed
    定义允许处理查询的时间。如果时间过去了
    查询响应完成,可能返回部分信息。
  • debug
    在响应中请求其他调试信息。
    指定debug = timing参数只返回时间信息;
    指定debug = results参数为返回的每个文档返回“说明”信息;
    指定debug = query参数返回所有调试信息。
    可选参数:query; timing; results; all
    *hl
    是否高亮
    写法:hl=truehl.<field_name>,<field_name2>
  • defType
    用于选择要用于处理查询的查询解析器类型
    可选参数:dismaxedismax
    Solr默认有三种查询解析器(Query Parser):
    • Standard Query Parser
    • DisMax Query Parser
    • Extended DisMax Query Parser (eDisMax)
      第一种是标准的Parser,最后一种是最强大的,也是Sunspot默认使用的Parser。
分组查询:

stats=true
stats.field=<field_name>
多组
facet=true
facet.field=

特殊符号:

+ - * ? && || () {} ^ " ~ : /

+ 必须满足
- 剔除
? 匹配单个字符
样例:te?ttex?
*匹配0到多个字符
~
1’ 模糊匹配
样例:<value>~<0~1>
2’ 临近检索
样例:<value>~<0~10>
^权重
^=指定分数
[number TO number]指定范围
/转义字符

逻辑操作:

AND/&& 与
OR/ || 或
NOT/! 非

4. solr schema配置详解

参考链接:
Solr高效利用:Solr实现SQL的查询与统计[转]
Solr查询

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容