• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | XML Messages: Add documents
  1. Notes
  2. Example of an XML message for adding new documents
  3. Add new documents using the update request handler
  4. Add new documents using the update request handler (stream.body)

  1. Notes
    Visit this Solr wiki page for more information: https://cwiki.apache.org/confluence/display/solr/UpdateXmlMessages

    Here's the structure of the add operation:
    <add overwrite="" commitWithin="">
        <doc boost="">
            <field name="" boost="">

    Optional attributes for the "add" element:
    • overwrite: (default: true) — if true, the new version of the document will replace the existing one.

    • commitWithin: (milliseconds) time for the document to be committed.

    Optional attributes for the "doc" element:
    • boost: (default: 1.0) a float number for the document boost value.

    Optional attributes for the "field" element:
    • boost: (default: 1.0) a float number for the field boost value.
  2. Example of an XML message for adding new documents
    Example: (Make sure that the fields "id", "field1", and "field2" are defined in your SchemaXml).
    <add>
        <doc>
            <field name="id">1</field>
            <field name="field1">field1 1-1</field>
            <field name="field1">field1 1-2</field>
            <field name="field2">field2 1</field>
            <field name="dynamicField1_s">dynamic_field1 1</field>
            <field name="dynamicField2_s">dynamic_field2 1</field>
        </doc>
    
        <doc>
            <field name="id">2</field>
            <field name="field1">field1 2-1</field>
            <field name="field1">field1 2-1</field>
            <field name="field2">field2 2</field>
            <field name="dynamicField1_s">dynamic_field1 2</field>
            <field name="dynamicField2_s">dynamic_field2 2</field>
        </doc>
    </add>
  3. Add new documents using the update request handler
    Here's an example of an http request:
    $ curl http://localhost:8983/solr/COLLECTION-NAME/update?commit=true \
    -H "Content-Type: text/xml" \
    --data-binary '<add><doc><field name="id">1</field><field name="data_s">alpha1</field></doc></add>'
  4. Add new documents using the update request handler (stream.body)
    Here's an example of an http request that uses the parameter stream.body:
    http://localhost:8983/solr/COLLECTION-NAME/update?update.contentType=text/xml&stream.body=<add><doc><field name="id">2</field><field name="data_s">alpha2</field></doc></add>

    In order for this request to work, you need to enable Streaming in "solrconfig.xml":
    <requestParsers enableStreamBody="true" />

    If you want to update the "solrconfig.xml" file directly in the Configset, make sure to reload all collections that use the updated Configset.
    Visit this page for more details: http://lucene.apache.org/solr/guide/8_5/requestdispatcher-in-solrconfig.html
© 2025  mtitek