Xapiand provides data manipulation and search capabilities in near real time. By default, you can expect a one second delay (refresh interval) from the time you index/update/delete your data until the time that it appears in your search results. This is an important distinction from other platforms like SQL wherein data is immediately available after a transaction is completed.
We’ve previously seen how we can index a single document. Let’s recall that command again:
The above will index the specified document into the user index, with the ID of
John. If we then executed the above command again with a different (or same)
document, Xapiand will replace (i.e. reindex) a new document on top of the
existing one with the ID of
The above completely overwrites the existent document with the ID of
the new one.
If, on the other hand, we use a different ID, a new document will be indexed and the existing document(s) already in the index remains untouched.
The above indexes a new document with an ID of
When indexing, the ID part is optional. If not specified, Xapiand will generate an ID and then use it to index the document. The actual ID Xapiand generates (or whatever we specified explicitly in the previous examples) is returned as part of the index API call.
This example shows how to index a document without an explicit ID:
Note that in the above case, we are using the
POST verb instead of
as we’re not specifying an explicit ID.
In addition to being able to index and replace documents, we can also update existing documents.
This example shows how to update our previous document (ID of
John) by adding
a gender field to it and leaving the name intact:
And the following example shows how to update the same document by adding an age field to it and at the same time changing the name from simply “John” to “Johnny Doe”:
Updating With Scripts
Updates can also be performed by using simple scripts. This example uses a script to increment the age by 5 and at the same time change the name:
In the above example,
_doc is the current document and
_old_doc refers to
the previous document that is about to be updated.
Deleting a document is fairly straightforward. This example shows how to delete
our previous user with the ID of