Description Usage Arguments Details The Elasticsearch v5 split References Examples
Store queries into an index then, via the percolate API, define documents to retrieve these queries.
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 | percolate_register(
conn,
index,
id,
type = NULL,
body = list(),
routing = NULL,
preference = NULL,
ignore_unavailable = NULL,
percolate_format = NULL,
refresh = NULL,
...
)
percolate_match(
conn,
index,
type = NULL,
body,
routing = NULL,
preference = NULL,
ignore_unavailable = NULL,
percolate_format = NULL,
...
)
percolate_list(conn, index, ...)
percolate_count(conn, index, type, body, ...)
percolate_delete(conn, index, id, ...)
|
conn |
an Elasticsearch connection object, see |
index |
Index name. Required |
id |
A precolator id. Required |
type |
Document type. Required |
body |
Body json, or R list. |
routing |
(character) In case the percolate queries are partitioned by a custom routing value, that routing option makes sure that the percolate request only gets executed on the shard where the routing value is partitioned to. This means that the percolate request only gets executed on one shard instead of all shards. Multiple values can be specified as a comma separated string, in that case the request can be be executed on more than one shard. |
preference |
(character) Controls which shard replicas are preferred to execute the request on. Works the same as in the search API. |
ignore_unavailable |
(logical) Controls if missing concrete indices should silently be ignored. Same as is in the search API. |
percolate_format |
(character) If ids is specified then the matches array in the percolate response will contain a string array of the matching ids instead of an array of objects. This can be useful to reduce the amount of data being send back to the client. Obviously if there are two percolator queries with same id from different indices there is no way to find out which percolator query belongs to what index. Any other value to percolate_format will be ignored. |
refresh |
If |
... |
Curl options. Or in |
Additional body options, pass those in the body. These aren't query string parameters:
filter - Reduces the number queries to execute during percolating. Only the percolator queries that match with the filter will be included in the percolate execution. The filter option works in near realtime, so a refresh needs to have occurred for the filter to included the latest percolate queries.
query - Same as the filter option, but also the score is computed. The computed scores can then be used by the track_scores and sort option.
size - Defines to maximum number of matches (percolate queries) to be returned. Defaults to unlimited.
track_scores - Whether the _score is included for each match. The _score is based on the query and represents how the query matched the percolate query's metadata, not how the document (that is being percolated) matched the query. The query option is required for this option. Defaults to false.
sort - Define a sort specification like in the search API. Currently only sorting _score reverse (default relevancy) is supported. Other sort fields will throw an exception. The size and query option are required for this setting. Like track_score the score is based on the query and represents how the query matched to the percolate query's metadata and not how the document being percolated matched to the query.
aggs - Allows aggregation definitions to be included. The aggregations are based on the matching percolator queries, look at the aggregation documentation on how to define aggregations.
highlight - Allows highlight definitions to be included. The document being percolated is being highlight for each matching query. This allows you to see how each match is highlighting the document being percolated. See highlight documentation on how to define highlights. The size option is required for highlighting, the performance of highlighting in the percolate API depends of how many matches are being highlighted.
In Elasticsearch < v5, there's a certain set of percolate APIs available, while in Elasticsearch >= v5, there's a different set of APIs available.
Internally within these percolate functions we detect your Elasticsearch version, then use the appropriate APIs
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | ## Not run:
x <- connect(errors = "complete")
##### Elasticsearch < v5
if (x$es_ver() < 500) {
# typical usage
## create an index first
if (index_exists(x, "myindex")) index_delete(x, "myindex")
mapping <- '{
"mappings": {
"mytype": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
}'
index_create(x, "myindex", body = mapping)
## register a percolator
perc_body = '{
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
}'
percolate_register(x, index = "myindex", type = "mytype",
id = 1, body = perc_body)
## register another
perc_body2 <- '{
"query" : {
"match" : {
"message" : "jane doe"
}
}
}'
percolate_register(x, index = "myindex", type = "mytype",
id = 2, body = perc_body2)
## match a document to a percolator
doc <- '{
"query": {
"percolate": {
"field": "query",
"document": {
"message" : "A new bonsai tree in the office"
}
}
}
}'
percolate_match(x, index = "myindex", type = "mytype", body = doc)
## List percolators - for an index, no type, can't do across indices
percolate_list(x, index = "myindex")$hits$hits
## Percolate counter
percolate_count(x, index = "myindex", type = "mytype", body = doc)$total
## delete a percolator
percolate_delete(x, index = "myindex", id = 2)
} # end ES < 5
##### Elasticsearch >= v5
if (x$es_ver() >= 500 && x$es_ver() <= 700) {
if (index_exists(x, "myindex")) index_delete(x, "myindex")
body <- '{
"mappings": {
"mytype": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}
}'
# create the index with mapping
index_create(x, "myindex", body = body)
## register a percolator
z <- '{
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
}'
percolate_register(x, index = "myindex", type = "mytype", id = 1, body = z)
## register another
x2 <- '{
"query" : {
"match" : {
"message" : "the office"
}
}
}'
percolate_register(x, index = "myindex", type = "mytype", id = 2, body = x2)
## match a document to a percolator
query <- '{
"query" : {
"percolate" : {
"field": "query",
"document": {
"message": "A new bonsai tree in the office"
}
}
}
}'
percolate_match(x, index = "myindex", body = query)
} # end ES >= 5
##### Elasticsearch >= v7
if (x$es_ver() >= 700) {
if (index_exists(x, "myindex")) index_delete(x, "myindex")
body <- '{
"mappings": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}'
# create the index with mapping
index_create(x, "myindex", body = body)
## register a percolator
z <- '{
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
}'
percolate_register(x, index = "myindex", id = 1, body = z)
## register another
x2 <- '{
"query" : {
"match" : {
"message" : "the office"
}
}
}'
percolate_register(x, index = "myindex", id = 2, body = x2)
## match a document to a percolator
query <- '{
"query" : {
"percolate" : {
"field": "query",
"document": {
"message": "A new bonsai tree in the office"
}
}
}
}'
percolate_match(x, index = "myindex", body = query)
} # end ES >= 7
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.