docs_create: Create a document

Description Usage Arguments References Examples

View source: R/docs_create.R

Description

Create a document

Usage

1
2
3
4
docs_create(index, type, id = NULL, body, version = NULL,
  version_type = NULL, op_type = NULL, routing = NULL,
  parent = NULL, timestamp = NULL, ttl = NULL, refresh = NULL,
  timeout = NULL, callopts = list(), ...)

Arguments

index

(character) The name of the index. Required

type

(character) The type of the document. Required

id

(numeric/character) The document ID. Can be numeric or character. Optional. if not provided, Elasticsearch creates the ID for you as a UUID.

body

The document.

version

(character) Explicit version number for concurrency control

version_type

(character) Specific version type. One of internal, external, external_gte, or force

op_type

(character) Operation type. One of create, or ...

routing

(character) Specific routing value

parent

(numeric) A parent document ID

timestamp

(date) Explicit timestamp for the document

ttl

(aka “time to live”) Expiration time for the document. Expired documents will be expunged automatically. The expiration date that will be set for a document with a provided ttl is relative to the timestamp of the document, meaning it can be based on the time of indexing or on any time provided. The provided ttl must be strictly positive and can be a number (in milliseconds) or any valid time value (e.g, 86400000, 1d).

refresh

(logical) Refresh the index after performing the operation

timeout

(character) Explicit operation timeout, e.g,. 5m (for 5 minutes)

callopts

Curl options passed on to httr::PUT()

...

Further args to query DSL

References

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
connect()
if (!index_exists('plos')) {
  plosdat <- system.file("examples", "plos_data.json", package = "elastic")
  invisible(docs_bulk(plosdat))
}

# give a document id
x <- docs_create(index='plos', type='article', id=1002, 
  body=list(id="12345", title="New title"))
x
# and the document is there now
docs_get(index='plos', type='article', id=1002)

# let Elasticsearch create the document id for you
x <- docs_create(index='plos', type='article', 
  body=list(id="6789", title="Some title"))
x
# and the document is there now
docs_get(index='plos', type='article', id=x$`_id`)

## End(Not run)

ropensci/elastic documentation built on Dec. 17, 2018, 11:08 a.m.