# NOT RUN {
# Used to check if a type/types exists in an index/indices
type_exists(index = "plos", type = "article")
type_exists(index = "plos", type = "articles")
type_exists(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="string"),
year = list(type="long")
)))
if (!index_exists("plos")) index_create("plos")
mapping_create(index = "plos", type = "citation", body=body)
### or as json
body <- '{
"citation": {
"properties": {
"journal": { "type": "string" },
"year": { "type": "long" }
}}}'
mapping_create(index = "plos", type = "citation", body=body)
mapping_get("plos", "citation")
## A bad mapping body
body <- list(things = list(properties = list(
journal = list("string")
)))
# mapping_create(index = "plos", type = "things", body=body)
# Get mappings
mapping_get('_all')
mapping_get(index = "plos")
mapping_get(index = c("shakespeare","plos"))
mapping_get(index = "shakespeare", type = "act")
mapping_get(index = "shakespeare", type = c("act","line"))
# Get field mappings
plosdat <- system.file("examples", "plos_data.json", package = "elastic")
docs_bulk(plosdat)
field_mapping_get(index = "_all", type=c('article', 'line'), field = "text")
field_mapping_get(index = "plos", type = "article", field = "title")
field_mapping_get(index = "plos", type = "article", field = "*")
field_mapping_get(index = "plos", type = "article", field = "title", include_defaults = TRUE)
field_mapping_get(type = c("article","record"), field = c("title","class"))
field_mapping_get(type = "a*", field = "t*")
# Create geospatial mapping
file <- system.file("examples", "gbif_geopoint.json", package = "elastic")
docs_bulk(file)
body <- '{
"properties" : {
"location" : { "type" : "geo_point" }
}
}'
mapping_create("gbifgeopoint", "record", body = body)
# }
Run the code above in your browser using DataLab