Post 工具
Solr 包含一个简单的命令行工具,用于将各种类型的内容 POST 到 Solr 服务器,该工具是 bin/solr CLI 的一部分。
| 此工具旨在供探索 Solr 功能的新用户使用,不作为将文档索引到生产系统的强大解决方案。 | 
| 您可能熟悉 SimplePostTool 和 bin/postUnix shell 脚本。虽然它仍然可用,但已被弃用,将在 Solr 10 中删除。 | 
要运行它,请打开一个窗口并输入
$ bin/solr post -url https://:8983/gettingstarted/update example/films/films.json这将连接到 localhost:8983 上的服务器。--help(或简写为 -h)选项将输出其使用信息(即,bin/solr post -h))。
使用 bin/solr post 工具
使用 bin/solr post 时,您必须指定 update 处理程序的完整路径的 url,或提供 c 集合/核心名称。
这将指定相同的目标集合:-url https://:8983/gettingstarted/update 或 -c gettingstarted。
bin/solr post 的基本用法是
usage: post
 -c,--name <NAME>                                 Name of the collection.
 -d,--delay <delay>                               If recursive then delay
                                                  will be the wait time
                                                  between posts.  default:
                                                  10 for web, 0 for files
    --dry-run                                     Performs a dry run of
                                                  the posting process
                                                  without actually sending
                                                  documents to Solr.  Only
                                                  works with files mode.
 -f,--format                                      sends application/json
                                                  content as Solr commands
                                                  to /update instead of
                                                  /update/json/docs.
 -ft,--filetypes <<type>[,<type>,...]>            default:
                                                  xml,json,jsonl,csv,pdf,d
                                                  oc,docx,ppt,pptx,xls,xls
                                                  x,odt,odp,ods,ott,otp,ot
                                                  s,rtf,htm,html,txt,log
 -h,--help                                        Print this message.
    --mode <mode>                                 Which mode the Post tool
                                                  is running in, 'files'
                                                  crawls local directory,
                                                  'web' crawls website,
                                                  'args' processes input
                                                  args, and 'stdin' reads
                                                  a command from standard
                                                  in. default: files.
 -o,--optimize                                    Issue an optimize at end
                                                  of posting documents.
    --out                                         sends Solr response
                                                  outputs to console.
 -p,--params <<key>=<value>[&<key>=<value>...]>   values must be
                                                  URL-encoded; these pass
                                                  through to Solr update
                                                  request.
 -r,--recursive <recursive>                       For web crawl, how deep
                                                  to go. default: 1
    --skip-commit                                 Do not 'commit', and
                                                  thus changes won't be
                                                  visible till a commit
                                                  occurs.
 -t,--type <content-type>                         Specify a specific
                                                  mimetype to use, such as
                                                  application/json.
 -u,--credentials <credentials>                   Credentials in the
                                                  format
                                                  username:password.
                                                  Example: --credentials
                                                  solr:SolrRocks
 -url,--solr-update-url <UPDATEURL>               Solr Update URL, the
                                                  full url to the update
                                                  handler, including the
                                                  /update.
 -v,--verbose                                     Enable more verbose
                                                  command output.使用 bin/solr post 的示例
有多种使用 bin/solr post 的方法。本节介绍几个示例。
索引 JSON
将所有 JSON 文件索引到 gettingstarted。
$ bin/solr post -url https://:8983/solr/gettingstarted/update *.json索引 XML
将文件扩展名为 .xml 的所有文档添加到名为 gettingstarted 的集合中。
$ bin/solr post -url https://:8983/solr/gettingstarted/update *.xml将所有以 article 开头且文件扩展名为 .xml 的文档添加到在端口 8984 上运行的 Solr 上的 gettingstarted 集合中。
$ bin/solr post -url https://:8984/solr/gettingstarted/update article*.xml发送 XML 参数以从 gettingstarted 中删除文档。
$ bin/solr post -url https://:8983/solr/gettingstarted/update --mode args --type application/xml '<delete><id>42</id></delete>'索引 CSV 和 JSON
将当前目录中的所有 CSV 和 JSON 文件索引到 gettingstarted
$ bin/solr post -c gettingstarted --filetypes json,csv .将制表符分隔的文件索引到 gettingstarted
$ bin/solr post -url https://:8984/solr/signals/update --params "separator=%09" --type text/csv data.tsv内容类型(-type)参数是必需的,才能将文件视为正确的类型,否则它将被忽略,并记录一条警告,因为它不知道 .tsv 文件是什么类型的内容。 CSV 处理程序支持 separator 参数,并通过 -params 设置传递。
索引富文档(PDF、Word、HTML 等)
将 PDF 文件索引到 gettingstarted。
$ bin/solr post -url https://:8983/solr/gettingstarted/update a.pdf自动检测文件夹中的内容类型,并递归扫描该文件夹中的文档以索引到 gettingstarted。
$ bin/solr post -url https://:8983/solr/gettingstarted/update afolder/自动检测文件夹中的内容类型,但将其限制为 PPT 和 HTML 文件,并索引到 gettingstarted。
$ bin/solr post -url https://:8983/solr/gettingstarted/update --filetypes ppt,html afolder/索引到受密码保护的 Solr(基本身份验证)
以用户“solr”和密码“SolrRocks”的身份索引 PDF
$ bin/solr post -u solr:SolrRocks -url https://:8983/solr/gettingstarted/update a.pdf爬取网站以索引文档
爬取 Apache Solr 网站,深入一层并将页面索引到 Solr 中。
请参阅试用 Solr Cell,以了解有关设置 Solr 以从网页中提取内容的更多信息。
$ bin/solr post --mode web -c gettingstarted --recursive 1 --delay 1 https://solr.apache.org/