multi-termvectors.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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,
  5. type and id. 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. "_type": "tweet",
  18. "_id": "2",
  19. "term_statistics": true
  20. },
  21. {
  22. "_index": "twitter",
  23. "_type": "tweet",
  24. "_id": "1",
  25. "fields": [
  26. "message"
  27. ]
  28. }
  29. ]
  30. }
  31. --------------------------------------------------
  32. // CONSOLE
  33. // TEST[setup:twitter]
  34. See the <<docs-termvectors,termvectors>> API for a description of possible parameters.
  35. The `_mtermvectors` endpoint can also be used against an index (in which case it
  36. is not required in the body):
  37. [source,js]
  38. --------------------------------------------------
  39. POST /twitter/_mtermvectors
  40. {
  41. "docs": [
  42. {
  43. "_type": "tweet",
  44. "_id": "2",
  45. "fields": [
  46. "message"
  47. ],
  48. "term_statistics": true
  49. },
  50. {
  51. "_type": "tweet",
  52. "_id": "1"
  53. }
  54. ]
  55. }
  56. --------------------------------------------------
  57. // CONSOLE
  58. // TEST[setup:twitter]
  59. And type:
  60. [source,js]
  61. --------------------------------------------------
  62. POST /twitter/tweet/_mtermvectors
  63. {
  64. "docs": [
  65. {
  66. "_id": "2",
  67. "fields": [
  68. "message"
  69. ],
  70. "term_statistics": true
  71. },
  72. {
  73. "_id": "1"
  74. }
  75. ]
  76. }
  77. --------------------------------------------------
  78. // CONSOLE
  79. // TEST[setup:twitter]
  80. If all requested documents are on same index and have same type and also the parameters are the same, the request can be simplified:
  81. [source,js]
  82. --------------------------------------------------
  83. POST /twitter/tweet/_mtermvectors
  84. {
  85. "ids" : ["1", "2"],
  86. "parameters": {
  87. "fields": [
  88. "message"
  89. ],
  90. "term_statistics": true
  91. }
  92. }
  93. --------------------------------------------------
  94. // CONSOLE
  95. // TEST[setup:twitter]
  96. Additionally, just like for the <<docs-termvectors,termvectors>>
  97. API, term vectors could be generated for user provided documents. The mapping used is
  98. determined by `_index` and `_type`.
  99. [source,js]
  100. --------------------------------------------------
  101. POST /_mtermvectors
  102. {
  103. "docs": [
  104. {
  105. "_index": "twitter",
  106. "_type": "tweet",
  107. "doc" : {
  108. "user" : "John Doe",
  109. "message" : "twitter test test test"
  110. }
  111. },
  112. {
  113. "_index": "twitter",
  114. "_type": "test",
  115. "doc" : {
  116. "user" : "Jane Doe",
  117. "message" : "Another twitter test ..."
  118. }
  119. }
  120. ]
  121. }
  122. --------------------------------------------------
  123. // CONSOLE
  124. // TEST[setup:twitter]