• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | Post documents to Solr (HTTP)
  1. Post documents to Solr (HTTP)

  1. Post documents to Solr (HTTP)
    The following section will show how to use the "post" command to index files.

    First, let's run Solr using the "schemaless" example:
    $ bin/solr start -e schemaless
    Creating Solr home directory /opt/solr/example/schemaless/solr
    
    Starting up Solr on port 8983 using command: "/opt/solr/bin/solr" start -p 8983 -s "/opt/solr/example/schemaless/solr"
    Waiting up to 180 seconds to see Solr running on port 8983 [|]
    Started Solr server on port 8983 (pid=11302). Happy searching!
    
    Created new core 'gettingstarted'
    
    Solr schemaless example launched successfully. Direct your Web browser to http://localhost:8983/solr to visit the Solr Admin UI

    Use the "post" command to index files:
    $ bin/post -c gettingstarted /opt/solr/example/exampledocs/*.xml
    /opt/jdk1.8.0_172/bin/java
        -classpath
        /opt/solr/dist/solr-core-9.8.1.jar
        -Dauto=yes
        -Dc=gettingstarted
        -Ddata=files
        org.apache.solr.util.SimplePostTool
        /opt/solr/example/exampledocs/gb18030-example.xml
        /opt/solr/example/exampledocs/hd.xml
        /opt/solr/example/exampledocs/ipod_other.xml
        /opt/solr/example/exampledocs/ipod_video.xml
        /opt/solr/example/exampledocs/manufacturers.xml
        /opt/solr/example/exampledocs/mem.xml
        /opt/solr/example/exampledocs/money.xml
        /opt/solr/example/exampledocs/monitor2.xml
        /opt/solr/example/exampledocs/monitor.xml
        /opt/solr/example/exampledocs/mp500.xml
        /opt/solr/example/exampledocs/sd500.xml
        /opt/solr/example/exampledocs/solr.xml
        /opt/solr/example/exampledocs/utf8-example.xml
        /opt/solr/example/exampledocs/vidcard.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
    
    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 monitor2.xml (application/xml) to [base]
    POSTing file monitor.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:00.849

    Note that the posted XML files have content similar to the following:
    <add>
      <doc>
        <field name="id">USD</field>
        <field name="name">One Dollar</field>
      </doc>
    </add>

    "post" command help:
    $ bin/post -help
    Usage:
      post -c <collection>|<core> [OPTIONS] <files|directories|urls|-d ["...",...]>
    or
      post -help
    
       collection/core name defaults to DEFAULT_SOLR_COLLECTION if not specified
    
    OPTIONS
    =======
      Solr options:
        -host <host> (default: localhost)
        -p or -port <port> (default: 8983)
        -url <base Solr update URL> (overrides collection, host, and port)
        -u or -user <user:pass> (sets BasicAuth credentials)
        -commit yes|no (default: yes)
    
      Web crawl options:
        -recursive <depth> (default: 1)
        -delay <seconds> (default: 10)
    
      Directory crawl options:
        -delay <seconds> (default: 0)
    
      stdin/args options:
        -type <content/type> (default: application/xml)
    
      Other options:
        -filetypes <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)
        -params "<key>=<value>[&<key>=<value>...]" (values must be URL-encoded; these pass through to Solr update request)
        -out yes|no (default: no; yes outputs Solr response to console)
        -format solr (sends application/json content as Solr commands to /update instead of /update/json/docs)
    
    Examples:
    
    * JSON file: bin/post -c wizbang events.json
    
    * XML files: bin/post -c records article*.xml
    
    * CSV file: bin/post -c signals LATEST-signals.csv
    
    * Directory of files: bin/post -c myfiles ~/Documents
    
    * Web crawl: bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1
    
    * Standard input (stdin): echo '{commit: {}}' | bin/post -c my_collection -type application/json -out yes -d
    
    * Data as string: bin/post -c signals -type text/csv -out yes -d $'id,value\n1,0.47'
© 2025  mtitek