Multi termvectors API

Multi termvectors API

Multi termvectors API允许一次获得多个词条向量。检索词条向量的文档由索引 、类型和ID指定。但文件也可以在请求本身中人为地提供。 响应包括一个具有所有获取的术语的docs数组,每个元素具有由termvectors API提供的结构。这是一个例子:

  1. POST /_mtermvectors
  2. {
  3. "docs": [
  4. {
  5. "_index": "twitter",
  6. "_type": "tweet",
  7. "_id": "2",
  8. "term_statistics": true
  9. },
  10. {
  11. "_index": "twitter",
  12. "_type": "tweet",
  13. "_id": "1",
  14. "fields": [
  15. "message"
  16. ]
  17. }
  18. ]
  19. }

有关可能的参数的描述,请参阅termvectors API。

_mtermvectors端点也可以针对索引使用(在这种情况下,它不需要在主体中):

  1. POST /twitter/_mtermvectors
  2. {
  3. "docs": [
  4. {
  5. "_type": "tweet",
  6. "_id": "2",
  7. "fields": [
  8. "message"
  9. ],
  10. "term_statistics": true
  11. },
  12. {
  13. "_type": "tweet",
  14. "_id": "1"
  15. }
  16. ]
  17. }

以及类型:

  1. POST /twitter/tweet/_mtermvectors
  2. {
  3. "docs": [
  4. {
  5. "_id": "2",
  6. "fields": [
  7. "message"
  8. ],
  9. "term_statistics": true
  10. },
  11. {
  12. "_id": "1"
  13. }
  14. ]
  15. }

如果所有请求的文档都在相同的索引并且具有相同的类型,并且参数是相同的,则可以简化请求:

  1. POST /twitter/tweet/_mtermvectors
  2. {
  3. "ids" : ["1", "2"],
  4. "parameters": {
  5. "fields": [
  6. "message"
  7. ],
  8. "term_statistics": true
  9. }
  10. }

此外,就像对于termvectors API一样,可以为用户提供的文档生成词条向量。所使用的映射由_index_type确定。

  1. POST /_mtermvectors
  2. {
  3. "docs": [
  4. {
  5. "_index": "twitter",
  6. "_type": "tweet",
  7. "doc" : {
  8. "user" : "John Doe",
  9. "message" : "twitter test test test"
  10. }
  11. },
  12. {
  13. "_index": "twitter",
  14. "_type": "test",
  15. "doc" : {
  16. "user" : "Jane Doe",
  17. "message" : "Another twitter test ..."
  18. }
  19. }
  20. ]
  21. }