Search_template: Search or validate templates

Description Usage Arguments Template search Template render Pre-registered templates References See Also Examples

View source: R/search_template.R

Description

Search or validate templates

Usage

1
2
3
4
5
6
7
8
9

Arguments

body

Query, either a list or json.

raw

(logical) If FALSE (default), data is parsed to list. If TRUE, then raw JSON returned

...

Curl args passed on to httr::POST()

template

(character) a template name

Template search

With Search_template you can search with a template, using mustache templating. Added in Elasticsearch v1.1

Template render

With Search_template_render you validate a template without conducting the search. Added in Elasticsearch v2.0

Pre-registered templates

Register a template with Search_template_register. You can get the template with Search_template_get and delete the template with Search_template_delete

You can also pre-register search templates by storing them in the config/scripts directory, in a file using the .mustache extension. In order to execute the stored template, reference it by it's name under the template key, like "file": "templateName", ...

References

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html

See Also

Search(), Search_uri()

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
## Not run: 
if (!index_exists("iris")) {
  invisible(docs_bulk(iris, "iris"))
}

body1 <- '{
  "inline" : {
    "query": { "match" : { "{{my_field}}" : "{{my_value}}" } },
    "size" : "{{my_size}}"
  },
  "params" : {
    "my_field" : "Species",
    "my_value" : "setosa",
    "my_size" : 3
  }
}'
Search_template(body = body1)

body2 <- '{
 "inline": {
   "query": {
      "match": {
          "Species": "{{query_string}}"
      }
   }
 },
 "params": {
   "query_string": "versicolor"
 }
}'
Search_template(body = body2)

# pass in a list
mylist <- list(
  inline = list(query = list(match = list(`{{my_field}}` = "{{my_value}}"))),
  params = list(my_field = "Species", my_value = "setosa", my_size = 3L)
)
Search_template(body = mylist)

## Validating templates w/ Search_template_render()
Search_template_render(body = body1)
Search_template_render(body = body2)

## pre-registered templates
### register a template
body3 <- '{
  "template": {
     "query": {
         "match": {
             "Species": "{{query_string}}"
         }
     }
   }
}'
Search_template_register('foobar', body = body3)

### get template
Search_template_get('foobar')

### use the template
body4 <- '{
 "id": "foobar",
  	"params": {
      "query_string": "setosa"
  }
}'
Search_template(body = body4)

### delete the template
Search_template_delete('foobar')

## End(Not run)

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