multi-termvectors.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. [[docs-multi-termvectors]]
  2. == Multi termvectors API
  3. Multi termvectors API allows to get multiple termvectors at once. The
  4. documents from which to retrieve the term vectors are specified by an index and id.
  5. But the documents could also be artificially provided in the request itself.
  6. The response includes a `docs`
  7. array with all the fetched termvectors, each element having the structure
  8. provided by the <<docs-termvectors,termvectors>>
  9. API. Here is an example:
  10. [source,js]
  11. --------------------------------------------------
  12. POST /_mtermvectors
  13. {
  14. "docs": [
  15. {
  16. "_index": "twitter",
  17. "_id": "2",
  18. "term_statistics": true
  19. },
  20. {
  21. "_index": "twitter",
  22. "_id": "1",
  23. "fields": [
  24. "message"
  25. ]
  26. }
  27. ]
  28. }
  29. --------------------------------------------------
  30. // CONSOLE
  31. // TEST[setup:twitter]
  32. See the <<docs-termvectors,termvectors>> API for a description of possible parameters.
  33. The `_mtermvectors` endpoint can also be used against an index (in which case it
  34. is not required in the body):
  35. [source,js]
  36. --------------------------------------------------
  37. POST /twitter/_mtermvectors
  38. {
  39. "docs": [
  40. {
  41. "_id": "2",
  42. "fields": [
  43. "message"
  44. ],
  45. "term_statistics": true
  46. },
  47. {
  48. "_id": "1"
  49. }
  50. ]
  51. }
  52. --------------------------------------------------
  53. // CONSOLE
  54. // TEST[setup:twitter]
  55. If all requested documents are on same index and also the parameters are the same, the request can be simplified:
  56. [source,js]
  57. --------------------------------------------------
  58. POST /twitter/_mtermvectors
  59. {
  60. "ids" : ["1", "2"],
  61. "parameters": {
  62. "fields": [
  63. "message"
  64. ],
  65. "term_statistics": true
  66. }
  67. }
  68. --------------------------------------------------
  69. // CONSOLE
  70. // TEST[setup:twitter]
  71. Additionally, just like for the <<docs-termvectors,termvectors>>
  72. API, term vectors could be generated for user provided documents.
  73. The mapping used is determined by `_index`.
  74. [source,js]
  75. --------------------------------------------------
  76. POST /_mtermvectors
  77. {
  78. "docs": [
  79. {
  80. "_index": "twitter",
  81. "doc" : {
  82. "user" : "John Doe",
  83. "message" : "twitter test test test"
  84. }
  85. },
  86. {
  87. "_index": "twitter",
  88. "doc" : {
  89. "user" : "Jane Doe",
  90. "message" : "Another twitter test ..."
  91. }
  92. }
  93. ]
  94. }
  95. --------------------------------------------------
  96. // CONSOLE
  97. // TEST[setup:twitter]