玩转Apache Solr 6.5.1

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: 以下都是基于linux环境参考链接:http://lucene.apache.org/solr/quickstart.html目录:solr 基本命令总结solr 命令参数详解solr 查询语法详解solr schema配置详解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查询

相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
目录
相关文章
|
12月前
|
机器学习/深度学习 人工智能 编解码
【搜索引擎】Apache Solr 神经搜索
【搜索引擎】Apache Solr 神经搜索
|
12月前
|
安全 Linux API
​Apache Solr未授权上传漏洞复现及验证POC编写
​Apache Solr未授权上传漏洞复现及验证POC编写
|
Apache 安全 应用服务中间件
|
Web App开发 应用服务中间件 PHP
|
Apache 数据格式 算法
|
关系型数据库 MySQL Apache
Apache solr(二).
上一篇试着进行了solr的安装和配置,以及如何solr的检索,今天试着简单的将solr连接MySQL数据库(才尝试了单表、一对多和多对多的还有待研究) 1、MySQL的目录结构   2、新建一个democore  3、在solr服务器http://localhost:8983/sol...
1053 0
|
存储 Java Apache
Apache solr(一).
概念:Apache Solr 是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。Apache Solr 中存储的资源是以 Document 为对象进行存储的。
1399 0
|
分布式计算 大数据 Apache
【Spark Summit East 2017】使用Spark MLlib和Apache Solr构建实时实体类型识别系统
本讲义出自Khalifeh Aljadda在Spark Summit East 2017上的演讲,由于实体查询系统中的查询一般比较短,所以由于缺少上下文信息,所以不适合使用传统的bag-of-words模型来确定实体类型,本讲义介绍了一个新颖的实体类型识别系统,该系统使用Spark MLlib和Apache Solr构建,能够结合不同来源的线索来分析出需要查询实体。
2426 0

热门文章

最新文章

推荐镜像

更多