From 2d568ece2db171775b8216aef8cf72be2d369c68 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 14 Sep 2016 11:23:25 -0400 Subject: [PATCH] CONSOLEify some search docs * search/search.asciidoc * search/request-body.asciidoc * search/explain.asciidoc * search/search-shards.asciidoc --- docs/reference/search/explain.asciidoc | 65 +++++++--- docs/reference/search/request-body.asciidoc | 30 +++-- docs/reference/search/search-shards.asciidoc | 120 ++++++++++--------- docs/reference/search/search.asciidoc | 20 +++- 4 files changed, 152 insertions(+), 83 deletions(-) diff --git a/docs/reference/search/explain.asciidoc b/docs/reference/search/explain.asciidoc index 93350719cdb..558071eedcf 100644 --- a/docs/reference/search/explain.asciidoc +++ b/docs/reference/search/explain.asciidoc @@ -15,35 +15,70 @@ Full query example: [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/twitter/tweet/1/_explain' -d '{ +GET /twitter/tweet/0/_explain +{ "query" : { - "term" : { "message" : "search" } + "match" : { "message" : "elasticsearch" } } -}' +} -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] This will yield the following result: [source,js] -------------------------------------------------- { - "matches" : true, + "_index" : "twitter", + "_type" : "tweet", + "_id" : "0", + "matched" : true, "explanation" : { - "value" : 0.15342641, - "description" : "fieldWeight(message:search in 0), product of:", + "value" : 1.55077, + "description" : "sum of:", "details" : [ { - "value" : 1.0, - "description" : "tf(termFreq(message:search)=1)" + "value" : 1.55077, + "description" : "weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:", + "details" : [ { + "value" : 1.55077, + "description" : "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:", + "details" : [ { + "value" : 1.3862944, + "description" : "idf(docFreq=1, docCount=5)", + "details" : [ ] + }, { + "value" : 1.1186441, + "description" : "tfNorm, computed from:", + "details" : [ + { "value" : 1.0, "description" : "termFreq=1.0", "details" : [ ] }, + { "value" : 1.2, "description" : "parameter k1", "details" : [ ] }, + { "value" : 0.75, "description" : "parameter b", "details" : [ ] }, + { "value" : 5.4, "description" : "avgFieldLength", "details" : [ ] }, + { "value" : 4.0, "description" : "fieldLength", "details" : [ ] } + ] + } ] + } ] }, { - "value" : 0.30685282, - "description" : "idf(docFreq=1, maxDocs=1)" - }, { - "value" : 0.5, - "description" : "fieldNorm(field=message, doc=0)" + "value" : 0.0, + "description" : "match on required clause, product of:", + "details" : [ { + "value" : 0.0, + "description" : "# clause", + "details" : [ ] + }, { + "value" : 1.0, + "description" : "_type:tweet, product of:", + "details" : [ + { "value" : 1.0, "description" : "boost", "details" : [ ] }, + { "value" : 1.0, "description" : "queryNorm", "details" : [ ] } + ] + } ] } ] } } -------------------------------------------------- +// TESTRESPONSE There is also a simpler way of specifying the query via the `q` parameter. The specified `q` parameter value is then parsed as if the @@ -52,8 +87,10 @@ explain api: [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/twitter/tweet/1/_explain?q=message:search' +GET /twitter/tweet/0/_explain?q=message:search -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] This will yield the same result as the previous request. diff --git a/docs/reference/search/request-body.asciidoc b/docs/reference/search/request-body.asciidoc index a9adc157bd3..852710df70b 100644 --- a/docs/reference/search/request-body.asciidoc +++ b/docs/reference/search/request-body.asciidoc @@ -7,41 +7,49 @@ example: [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{ +GET /twitter/tweet/_search +{ "query" : { "term" : { "user" : "kimchy" } } } -' -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] And here is a sample response: [source,js] -------------------------------------------------- { + "took": 1, + "timed_out": false, "_shards":{ - "total" : 5, - "successful" : 5, + "total" : 1, + "successful" : 1, "failed" : 0 }, "hits":{ "total" : 1, + "max_score": 1.3862944, "hits" : [ { "_index" : "twitter", "_type" : "tweet", - "_id" : "1", + "_id" : "0", + "_score": 1.3862944, "_source" : { "user" : "kimchy", - "postDate" : "2009-11-15T14:12:12", - "message" : "trying out Elasticsearch" + "message": "trying out Elasticsearch", + "date" : "2009-11-15T14:12:12", + "likes" : 0 } } ] } } -------------------------------------------------- +// TESTRESPONSE[s/"took": 1/"took": $body.took/] [float] === Parameters @@ -105,8 +113,10 @@ matching document was found (per shard). [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/_search?q=tag:wow&size=0&terminate_after=1' +GET /_search?q=message:elasticsearch&size=0&terminate_after=1 -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] The response will not contain any hits as the `size` was set to `0`. The `hits.total` will be either equal to `0`, indicating that there were no @@ -128,12 +138,12 @@ be set to `true` in the response. }, "hits": { "total": 1, - "max_score": 0, + "max_score": 0.0, "hits": [] } } -------------------------------------------------- - +// TESTRESPONSE[s/"took": 3/"took": $body.took/] include::request/query.asciidoc[] diff --git a/docs/reference/search/search-shards.asciidoc b/docs/reference/search/search-shards.asciidoc index 718d47a986f..c07c3755a26 100644 --- a/docs/reference/search/search-shards.asciidoc +++ b/docs/reference/search/search-shards.asciidoc @@ -14,49 +14,27 @@ Full example: [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/twitter/_search_shards' +GET /twitter/_search_shards -------------------------------------------------- +// CONSOLE +// TEST[s/^/PUT twitter\n/] This will yield the following result: [source,js] -------------------------------------------------- { - "nodes": { - "JklnKbD7Tyqi9TP3_Q_tBg": { - "name": "Rl'nnd", - "transport_address": "inet[/192.168.1.113:9300]" - } - }, + "nodes": ..., "shards": [ [ { "index": "twitter", "node": "JklnKbD7Tyqi9TP3_Q_tBg", "primary": true, - "relocating_node": null, - "shard": 3, - "state": "STARTED" - } - ], - [ - { - "index": "twitter", - "node": "JklnKbD7Tyqi9TP3_Q_tBg", - "primary": true, - "relocating_node": null, - "shard": 4, - "state": "STARTED" - } - ], - [ - { - "index": "twitter", - "node": "JklnKbD7Tyqi9TP3_Q_tBg", - "primary": true, - "relocating_node": null, "shard": 0, - "state": "STARTED" + "state": "STARTED", + "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"}, + "relocating_node": null } ], [ @@ -64,52 +42,81 @@ This will yield the following result: "index": "twitter", "node": "JklnKbD7Tyqi9TP3_Q_tBg", "primary": true, - "relocating_node": null, - "shard": 2, - "state": "STARTED" - } - ], - [ - { - "index": "twitter", - "node": "JklnKbD7Tyqi9TP3_Q_tBg", - "primary": true, - "relocating_node": null, "shard": 1, - "state": "STARTED" + "state": "STARTED", + "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"}, + "relocating_node": null + } + ], + [ + { + "index": "twitter", + "node": "JklnKbD7Tyqi9TP3_Q_tBg", + "primary": true, + "shard": 2, + "state": "STARTED", + "allocation_id": {"id":"Nwl0wbMBTHCWjEEbGYGapg"}, + "relocating_node": null + } + ], + [ + { + "index": "twitter", + "node": "JklnKbD7Tyqi9TP3_Q_tBg", + "primary": true, + "shard": 3, + "state": "STARTED", + "allocation_id": {"id":"bU_KLGJISbW0RejwnwDPKw"}, + "relocating_node": null + } + ], + [ + { + "index": "twitter", + "node": "JklnKbD7Tyqi9TP3_Q_tBg", + "primary": true, + "shard": 4, + "state": "STARTED", + "allocation_id": {"id":"DMs7_giNSwmdqVukF7UydA"}, + "relocating_node": null } ] ] } -------------------------------------------------- +// TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/] +// TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/] +// TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/] +// TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/] +// TESTRESPONSE[s/Nwl0wbMBTHCWjEEbGYGapg/$body.shards.2.0.allocation_id.id/] +// TESTRESPONSE[s/bU_KLGJISbW0RejwnwDPKw/$body.shards.3.0.allocation_id.id/] +// TESTRESPONSE[s/DMs7_giNSwmdqVukF7UydA/$body.shards.4.0.allocation_id.id/] And specifying the same request, this time with a routing value: [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/twitter/_search_shards?routing=foo,baz' +GET /twitter/_search_shards?routing=foo,baz -------------------------------------------------- +// CONSOLE +// TEST[s/^/PUT twitter\n/] This will yield the following result: [source,js] -------------------------------------------------- { - "nodes": { - "JklnKbD7Tyqi9TP3_Q_tBg": { - "name": "Rl'nnd", - "transport_address": "inet[/192.168.1.113:9300]" - } - }, + "nodes": ..., "shards": [ [ { "index": "twitter", "node": "JklnKbD7Tyqi9TP3_Q_tBg", "primary": true, - "relocating_node": null, - "shard": 2, - "state": "STARTED" + "shard": 0, + "state": "STARTED", + "allocation_id": {"id":"0TvkCyF7TAmM1wHP4a42-A"}, + "relocating_node": null } ], [ @@ -117,14 +124,19 @@ This will yield the following result: "index": "twitter", "node": "JklnKbD7Tyqi9TP3_Q_tBg", "primary": true, - "relocating_node": null, - "shard": 4, - "state": "STARTED" + "shard": 1, + "state": "STARTED", + "allocation_id": {"id":"fMju3hd1QHWmWrIgFnI4Ww"}, + "relocating_node": null } ] ] } -------------------------------------------------- +// TESTRESPONSE[s/"nodes": ...,/"nodes": $body.nodes,/] +// TESTRESPONSE[s/JklnKbD7Tyqi9TP3_Q_tBg/$body.shards.0.0.node/] +// TESTRESPONSE[s/0TvkCyF7TAmM1wHP4a42-A/$body.shards.0.0.allocation_id.id/] +// TESTRESPONSE[s/fMju3hd1QHWmWrIgFnI4Ww/$body.shards.1.0.allocation_id.id/] This time the search will only be executed against two of the shards, because routing values have been specified. diff --git a/docs/reference/search/search.asciidoc b/docs/reference/search/search.asciidoc index 40118e76931..eccba57dee1 100644 --- a/docs/reference/search/search.asciidoc +++ b/docs/reference/search/search.asciidoc @@ -17,38 +17,48 @@ twitter index: [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/twitter/_search?q=user:kimchy' +GET /twitter/_search?q=user:kimchy -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] We can also search within specific types: [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/twitter/tweet,user/_search?q=user:kimchy' +GET /twitter/tweet,user/_search?q=user:kimchy -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] We can also search all tweets with a certain tag across several indices (for example, when each user has his own index): [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/kimchy,elasticsearch/tweet/_search?q=tag:wow' +GET /kimchy,elasticsearch/tweet/_search?q=tag:wow -------------------------------------------------- +// CONSOLE +// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/] Or we can search all tweets across all available indices using `_all` placeholder: [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/_all/tweet/_search?q=tag:wow' +GET /_all/tweet/_search?q=tag:wow -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] Or even search across all indices and all types: [source,js] -------------------------------------------------- -$ curl -XGET 'http://localhost:9200/_search?q=tag:wow' +GET /_search?q=tag:wow -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] By default elasticsearch rejects search requests that would query more than 1000 shards. The reason is that such large numbers of shards make the job of