• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Maven
  • About
Apache Solr | XML Messages: Update documents
  1. Notes
  2. Example of an XML message to update an existing document
  3. Update a document using the update request handler
  4. Update a document using the update request handler (stream.body)

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

    Here's the structure of the update operation:
    <add commitWithin="">
        <doc boost="">
            <field name="" boost="" update="set|add|inc">

    Optional attributes for the "add" element:
    • 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.

    • update: "set" | "add" | "inc"

      With:
      • set: sets a value (if null remove the value, or, in the case of a multi-valued field, remove all the values).

      • add: adds a new value to a multi-valued field.

      • inc: increments a value by a specific number.

      Important: If none of the document "field" elements sets the "update" attribute, then the operation will be considered an "add" operation.
      Which means that the document will be added if it's a new document, or updated if it was already added (missing fields will be set to null or to a default value).
  2. Example of an XML message to update an existing document
    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" update="set">field1 1-1</field>
            <field name="field1" update="set">field1 1-2</field>
            <field name="dynamicField1_s" update="set">dynamicField1_s 1-1</field>
        </doc>
    
        <doc>
            <field name="id">2</field>
            <field name="field2" update="set">field2 2-1</field>
            <field name="dynamicField2_s" update="set">dynamicField2_s 2-1</field>
        </doc>
    
        <doc>
            <field name="id">3</field>
            <field name="field1" update="add">field1 3-1</field>
            <field name="field1" update="add">field1 3-2</field>
            <field name="field2" update="set">field2 3-1</field>
        </doc>
    </add>
  3. Update a document 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" update="set">beta</field></doc></add>'
  4. Update a document 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">1</field><field name="data_s" update="set">beta</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