Solr's Update-XML format

Using XML, you can send add, commit, optimize, and delete commands to Solr. Here is an XML sample for sending HTTP POST to Solr; this will add (or replace) documents:

<add overwrite="true">
  <doc boost="2.0">
    <field name="id">Artist:11650</field>
    <field name="type">Artist</field>
    <field name="a_name" boost="0.5">The Smashing Pumpkins</field>
    <!-- the date/time syntax MUST look just like this -->
    <field name="a_begin_date">2007-12-31T09:40:00Z</field>
  </doc>
  <doc>
    <field name="id">Artist:11651</field>
    <field name="type">Artist</field>
    <field name="a_begin_date">2007-12-31T09:40:00Z</field>
  </doc>
  <!-- more doc elements here as needed -->
</add>

Tip

A valid XML document has one root element. If you want to send multiple XML-based commands to Solr in the same message/file, you can wrap the commands in an arbitrarily named root element.

If you have a field in your schema defined as unique, and the overwrite attribute is set to true (the default), an incoming document will replace an existing document when both documents have the same unique field value.

Tip

If you are sure that you will be adding a document that is not a duplicate, then you can set overwrite to false to get a small performance improvement, since Solr won't check uniqueness of the unique key field.

The boost attribute affects the scoring of search results at query time. Providing a boost value, whether at the document or field level, is optional. The default value is 1.0, which is effectively a nonboost. Technically, documents are boosted at the field level. The effective boost value for a field is the document boost, multiplied by the field boost value.

Note

Specifying boosts here is called index-time boosting, which is rarely done as compared to the more flexible query-time boosting. Index-time boosting is less flexible because such boosting decisions must be decided at index-time and will apply to all of the queries. You'll learn more about boosting and scoring in Chapter 6, Search Relevancy.

Deleting documents

You can delete a document by its unique field and value. Here, we delete two documents:

<delete><id>Artist:11604</id><id>Artist:11603</id></delete>

A query can provide a more flexible way to specify which documents are to be deleted:

<delete><query>timestamp:[* TO NOW-12HOUR]</query></delete>

The previous delete query would delete all documents whose timestamps are older than 12 hours from the current time. More info on querying Solr can be found in Chapter 5, Searching.

The contents of the delete tag can be any number of id and query tags, so you can batch many deletions into one message to Solr.

Tip

If you want to delete the entire index during development (or perform major schema changes in production), simply delete the data directory while Solr is shut down.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.25.32