From e177d2ca402d070f932e64bd30a7d62a90c67ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 8 Feb 2017 16:06:11 +0100 Subject: [PATCH] Docs: CONSOLEify termvectors.asciidoc (#23046) --- docs/build.gradle | 1 - docs/reference/docs/termvectors.asciidoc | 76 +++++++++++++++++------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 641a6f24168..9e82276792a 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -99,7 +99,6 @@ buildRestTests.expectedUnconvertedCandidates = [ 'reference/docs/index_.asciidoc', 'reference/docs/multi-get.asciidoc', 'reference/docs/reindex.asciidoc', - 'reference/docs/termvectors.asciidoc', 'reference/docs/update-by-query.asciidoc', 'reference/docs/update.asciidoc', 'reference/index-modules/similarity.asciidoc', diff --git a/docs/reference/docs/termvectors.asciidoc b/docs/reference/docs/termvectors.asciidoc index 586f40432b3..50c2bd19308 100644 --- a/docs/reference/docs/termvectors.asciidoc +++ b/docs/reference/docs/termvectors.asciidoc @@ -8,16 +8,20 @@ realtime. This can be changed by setting `realtime` parameter to `false`. [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true' +GET /twitter/tweet/1/_termvectors -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] Optionally, you can specify the fields for which the information is retrieved either with a parameter in the url [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?fields=text,...' +GET /twitter/tweet/1/_termvectors?fields=message -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] or by adding the requested fields in the request body (see example below). Fields can also be specified with wildcards @@ -124,8 +128,8 @@ First, we create an index that stores term vectors, payloads etc. : [source,js] -------------------------------------------------- -curl -s -XPUT 'http://localhost:9200/twitter/' -d '{ - "mappings": { +PUT /twitter/ +{ "mappings": { "tweet": { "properties": { "text": { @@ -160,51 +164,58 @@ curl -s -XPUT 'http://localhost:9200/twitter/' -d '{ } } } -}' +} -------------------------------------------------- +// CONSOLE Second, we add some documents: [source,js] -------------------------------------------------- -curl -XPUT 'http://localhost:9200/twitter/tweet/1?pretty=true' -d '{ +PUT /twitter/tweet/1 +{ "fullname" : "John Doe", "text" : "twitter test test test " -}' +} -curl -XPUT 'http://localhost:9200/twitter/tweet/2?pretty=true' -d '{ +PUT /twitter/tweet/2 +{ "fullname" : "Jane Doe", "text" : "Another twitter test ..." -}' +} -------------------------------------------------- +// CONSOLE +// TEST[continued] The following request returns all information and statistics for field `text` in document `1` (John Doe): [source,js] -------------------------------------------------- - -curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true' -d '{ +GET /twitter/tweet/1/_termvectors +{ "fields" : ["text"], "offsets" : true, "payloads" : true, "positions" : true, "term_statistics" : true, "field_statistics" : true -}' +} -------------------------------------------------- +// CONSOLE +// TEST[continued] Response: [source,js] -------------------------------------------------- - { "_id": "1", "_index": "twitter", "_type": "tweet", "_version": 1, "found": true, + "took": 6, "term_vectors": { "text": { "field_statistics": { @@ -256,6 +267,9 @@ Response: } } -------------------------------------------------- +// TEST[continued] +// TESTRESPONSE[s/"took": 6/"took": "$body.took"/] + ================================================== .Generating term vectors on the fly @@ -268,14 +282,17 @@ Note that for the field `text`, the terms are not re-generated. [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true' -d '{ +GET /twitter/tweet/1/_termvectors +{ "fields" : ["text", "some_field_without_term_vectors"], "offsets" : true, "positions" : true, "term_statistics" : true, "field_statistics" : true -}' +} -------------------------------------------------- +// CONSOLE +// TEST[continued] ================================================== [[docs-termvectors-artificial-doc]] @@ -293,13 +310,16 @@ mapping will be dynamically created.* [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/twitter/tweet/_termvectors' -d '{ +GET /twitter/tweet/_termvectors +{ "doc" : { "fullname" : "John Doe", "text" : "twitter test test test" } -}' +} -------------------------------------------------- +// CONSOLE +// TEST[continued] -- [[docs-termvectors-per-field-analyzer]] @@ -314,7 +334,8 @@ vectors, the term vectors will be re-generated. [source,js] -------------------------------------------------- -curl -XGET 'http://localhost:9200/twitter/tweet/_termvectors' -d '{ +GET /twitter/tweet/_termvectors +{ "doc" : { "fullname" : "John Doe", "text" : "twitter test test test" @@ -323,8 +344,10 @@ curl -XGET 'http://localhost:9200/twitter/tweet/_termvectors' -d '{ "per_field_analyzer" : { "fullname": "keyword" } -}' +} -------------------------------------------------- +// CONSOLE +// TEST[continued] Response: @@ -335,12 +358,13 @@ Response: "_type": "tweet", "_version": 0, "found": true, + "took": 6, "term_vectors": { "fullname": { "field_statistics": { - "sum_doc_freq": 1, - "doc_count": 1, - "sum_ttf": 1 + "sum_doc_freq": 2, + "doc_count": 4, + "sum_ttf": 4 }, "terms": { "John Doe": { @@ -358,6 +382,11 @@ Response: } } -------------------------------------------------- +// TEST[continued] +// TESTRESPONSE[s/"took": 6/"took": "$body.took"/] +// TESTRESPONSE[s/"sum_doc_freq": 2/"sum_doc_freq": "$body.term_vectors.fullname.field_statistics.sum_doc_freq"/] +// TESTRESPONSE[s/"doc_count": 4/"doc_count": "$body.term_vectors.fullname.field_statistics.doc_count"/] +// TESTRESPONSE[s/"sum_ttf": 4/"sum_ttf": "$body.term_vectors.fullname.field_statistics.sum_ttf"/] ================================================== [[docs-termvectors-terms-filtering]] @@ -388,6 +417,8 @@ GET /imdb/movies/_termvectors } } -------------------------------------------------- +// CONSOLE +// TEST[skip:no imdb test index] Response: @@ -429,4 +460,5 @@ Response: } } -------------------------------------------------- +// TESTRESPONSE ==================================================