_idmay be set manually (
document.setId()) or, if not provided will be auto-generated when the record is persisted. Note that, if using numeric primary keys for your
_idvalue, they will be cast as strings on serialization.
Documentmodel is the primary object for creating and working with Documents. Let's say, again, we were going to create a new document in our index. We would do so, by first creating a
_idvalue, we would need to explicitly call
setId( myCustomId )to do so, or would need to provide an
_idkey in the struct provided to the
_idvalue. We can either retrieve using the
Documentobject or by interfacing with the
Clientobject directly. In either case, the result returned is a
Documentobject, i f found, or null if not found.
get()method with explicit arguments:
getmethod also accepts a struct of query parameters to pass to the document retrieval request. For example, we only want certain items returned in the document JSON, we can pass a
Documentinstance and re-save them.
patchmethod of the Client allows a user to update select fields, bypassing the need for a fully retrieved document. This is similar to an
UPDATE foo SET bar = 'xyz' WHERE id = :idquery on a relational database. The method requires an index name, identifier and a struct containing the keys to be updated:
processBulkOperationmethod allows you to send a payload of operations in one batch. Note that create, update, and index actions require a
sourcekey, where as
deletemethods only require an
operationkey. The schema of the
sourcekey follows the same schema's described in the Bulk API Documentation:
Documentobjects to the Client's
updateByQuerymethod can provide a powerful way to make bulk transformations on documents in your index. The
updateByQuerymethod requires the passing of a "script" argument, which is a struct containing two strings - the language and the script. Elasticsearch supports a number of languages however, most of the time, the "painless" language is the easiest choice.
isInPrintkey and created all documents which matched to use a default value of
ctx._sourceused in the script, which is a reference to the document being iterated in the update loop. More information on crafting complex, scripted, query-based updates can be found in the official elasticsearch documentation.
Documentobject may be used to delete a single item.
Documentinstance to the client:
SearchBuilder( more below ):
deleteByQuerymethods support a
waitForCompletionargument. By default, this is set to
true. When passed as false, however, the method will return a
Taskinstance, which can be used to follow up on the completion status of the action process.