multi-termvectors.asciidoc 3.0 KB

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