# NOT RUN {
x <- connect()
if (!index_exists(x, 'omdb')) {
omdb <- system.file("examples", "omdb.json", package = "elastic")
docs_bulk(x, omdb)
}
# no index or type given
body <- '{
"docs": [
{
"_index": "omdb",
"_type": "omdb",
"_id": "AVXdx8Eqg_0Z_tpMDyP_",
"term_statistics": true
},
{
"_index": "omdb",
"_type": "omdb",
"_id": "AVXdx8Eqg_0Z_tpMDyQ1",
"fields": [
"Plot"
]
}
]
}'
mtermvectors(x, body = body)
# index given, but not type
body <- '{
"docs": [
{
"_type": "omdb",
"_id": "AVXdx8Eqg_0Z_tpMDyP_",
"fields": [
"Plot"
],
"term_statistics": true
},
{
"_type": "omdb",
"_id": "AVXdx8Eqg_0Z_tpMDyQ1",
"fields": [
"Title"
]
}
]
}'
mtermvectors(x, 'omdb', body = body)
# index and type given
body <- '{
"docs": [
{
"_id": "AVXdx8Eqg_0Z_tpMDyP_",
"fields": [
"Plot"
],
"term_statistics": true
},
{
"_id": "AVXdx8Eqg_0Z_tpMDyQ1"
}
]
}'
mtermvectors(x, 'omdb', 'omdb', body = body)
# index and type given, parameters same, so can simplify
body <- '{
"ids" : ["AVXdx8Eqg_0Z_tpMDyP_", "AVXdx8Eqg_0Z_tpMDyQ1"],
"parameters": {
"fields": [
"Plot"
],
"term_statistics": true
}
}'
mtermvectors(x, 'omdb', 'omdb', body = body)
# 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",
"_type": "omdb",
"doc" : {
"Director" : "John Doe",
"Plot" : "twitter test test test"
}
},
{
"_index": "omdb",
"_type": "omdb",
"doc" : {
"Director" : "Jane Doe",
"Plot" : "Another twitter test ..."
}
}
]
}'
mtermvectors(x, body = body)
# }
Run the code above in your browser using DataLab