# NOT RUN {
# connection setup
(x <- connect())
# Used to check if a type/types exists in an index/indices
type_exists(x, index = "plos", type = "article")
type_exists(x, index = "plos", type = "articles")
type_exists(x, index = "shakespeare", type = "line")
# The put mapping API allows to register specific mapping definition for a specific type.
## a good mapping body
body <- list(citation = list(properties = list(
journal = list(type="text"),
year = list(type="long")
)))
if (!index_exists(x, "plos")) index_create(x, "plos")
mapping_create(x, index = "plos", type = "citation", body=body)
### or as json
body <- '{
"citation": {
"properties": {
"journal": { "type": "text" },
"year": { "type": "long" }
}}}'
mapping_create(x, index = "plos", type = "citation", body=body)
mapping_get(x, "plos", "citation")
## A bad mapping body
body <- list(things = list(properties = list(
journal = list("text")
)))
# mapping_create(x, index = "plos", type = "things", body=body)
# Get mappings
mapping_get(x, '_all')
mapping_get(x, index = "plos")
mapping_get(x, index = c("shakespeare","plos"))
# mapping_get(x, index = "shakespeare", type = "act")
# mapping_get(x, index = "shakespeare", type = c("act","line"))
# Get field mappings
plosdat <- system.file("examples", "plos_data.json", package = "elastic")
invisible(docs_bulk(x, plosdat))
field_mapping_get(x, index = "_all", type=c('article', 'line'), field = "text")
field_mapping_get(x, index = "plos", type = "article", field = "title")
field_mapping_get(x, index = "plos", type = "article", field = "*")
field_mapping_get(x, index = "plos", type = "article", field = "title", include_defaults = TRUE)
field_mapping_get(x, type = c("article","record"), field = c("title","class"))
field_mapping_get(x, type = "a*", field = "t*")
# Create geospatial mapping
if (index_exists(x, "gbifgeopoint")) index_delete(x, "gbifgeopoint")
file <- system.file("examples", "gbif_geopoint.json", package = "elastic")
index_create(x, "gbifgeopoint")
body <- '{
"properties" : {
"location" : { "type" : "geo_point" }
}
}'
mapping_create(x, "gbifgeopoint", "record", body = body)
invisible(docs_bulk(x, file))
# update_all_fields, see also ?fielddata
if (x$es_ver() < 603) {
mapping_create(x, "shakespeare", "record", update_all_types=TRUE, body = '{
"properties": {
"speaker": {
"type": "text",
"fielddata": true
}
}
}')
} else {
index_create(x, 'brownchair')
mapping_create(x, 'brownchair', 'brown', body = '{
"properties": {
"foo": {
"type": "text",
"fielddata": true
}
}
}')
}
# }
Run the code above in your browser using DataLab