mapping: Mapping management

Description Usage Arguments Details Examples

Description

Mapping management

Usage

1
2
3
4
5
6
7
8
mapping_create(index, type, body, update_all_types = FALSE, ...)

mapping_get(index = NULL, type = NULL, ...)

field_mapping_get(index = NULL, type = NULL, field,
  include_defaults = FALSE, ...)

type_exists(index, type, ...)

Arguments

index

(character) An index

type

(character) A document type

body

(list) Either a list or json, representing the query.

update_all_types

(logical) update all types. default: FALSE. This parameter is deprecated in ES v6.3.0 and higher, see https://github.com/elastic/elasticsearch/pull/28284

...

Curl options passed on to httr::HEAD() or other http verbs

field

(character) One or more field names

include_defaults

(logical) Whether to return default values

Details

Find documentation for each function at:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
## 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="text"),
 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": "text" },
      "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("text")
)))
# 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")
invisible(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
if (index_exists("gbifgeopoint")) index_delete("gbifgeopoint")
file <- system.file("examples", "gbif_geopoint.json", package = "elastic")
index_create("gbifgeopoint")
body <- '{
 "properties" : {
   "location" : { "type" : "geo_point" }
 }
}'
mapping_create("gbifgeopoint", "record", body = body)
invisible(docs_bulk(file))

# update_all_fields, see also ?fielddata
if (es_ver() < 603) {
 mapping_create("shakespeare", "record", update_all_types=TRUE, body = '{
   "properties": {
     "speaker": { 
       "type":     "text",
       "fielddata": true
     }
   }
 }')
} else {
 index_create('brownchair')
 mapping_create('brownchair', 'brown', body = '{
   "properties": {
     "foo": { 
       "type":     "text",
       "fielddata": true
     }
   }
 }')
}


## End(Not run)

ropensci/elastic documentation built on Aug. 11, 2018, 3:46 a.m.