# NOT RUN {
x <- connect()
if (index_exists(x, 'omdb')) index_delete(x, "omdb")
omdb <- system.file("examples", "omdb.json", package = "elastic")
omdb <- type_remover(omdb)
invisible(docs_bulk(x, omdb))
out <- Search(x, "omdb", size = 2)$hits$hits
ids <- vapply(out, "[[", "", "_id")
# no index
body <- '{
"docs": [
{
"_index": "omdb",
"_id": "%s",
"term_statistics": true
},
{
"_index": "omdb",
"_id": "%s",
"fields": [
"Plot"
]
}
]
}'
mtermvectors(x, body = sprintf(body, ids[1], ids[2]))
# index given
body <- '{
"docs": [
{
"_id": "%s",
"fields": [
"Plot"
],
"term_statistics": true
},
{
"_id": "%s",
"fields": [
"Title"
]
}
]
}'
mtermvectors(x, 'omdb', body = sprintf(body, ids[1], ids[2]))
# parameters same for both documents, so can simplify
body <- '{
"ids" : ["%s", "%s"],
"parameters": {
"fields": [
"Plot"
],
"term_statistics": true
}
}'
mtermvectors(x, 'omdb', body = sprintf(body, ids[1], ids[2]))
# you can give user provided documents via the 'docs' parameter
## though you have to give index and type that exist in your Elasticsearch
## instance
body <- '{
"docs": [
{
"_index": "omdb",
"doc" : {
"Director" : "John Doe",
"Plot" : "twitter test test test"
}
},
{
"_index": "omdb",
"doc" : {
"Director" : "Jane Doe",
"Plot" : "Another twitter test ..."
}
}
]
}'
mtermvectors(x, body = body)
# }
Run the code above in your browser using DataLab