浏览代码

[DOCS] Introduce basic ECS logs test (#59713)

Adds a new `my-index-00001` REST test for docs snippets.

This test can serve as a lightweight replacement for
our existing `twitter` REST tests.

The new dataset is:

* Based on Apache logs, which is better aligned with Elastic use cases
* Compliant with ECS
* Similar to the existing `twitter` data set, containing the same field data types
* Lightweight, which should keep existing test runtimes roughly the same

Also updates the search API reference docs to use the new test.
James Rodewig 5 年之前
父节点
当前提交
3113f9495d
共有 2 个文件被更改,包括 103 次插入31 次删除
  1. 43 0
      docs/build.gradle
  2. 60 31
      docs/reference/search/search.asciidoc

+ 43 - 0
docs/build.gradle

@@ -167,6 +167,49 @@ setupTwitter('twitter', 5)
 setupTwitter('big_twitter', 120)
 setupTwitter('huge_twitter', 1200)
 
+Closure setupMyIndex = { String name, int count ->
+  buildRestTests.setups[name] = '''
+  - do:
+        indices.create:
+          index: my-index-000001
+          body:
+            settings:
+              number_of_shards: 1
+              number_of_replicas: 1
+            mappings:
+              properties:
+                "@timestamp":
+                  type: date
+                message:
+                  type: text
+                user:
+                  properties:
+                    id:
+                      type: keyword
+                      doc_values: true
+  - do:
+        bulk:
+          index: my-index-000001
+          refresh: true
+          body: |'''
+  for (int i = 0; i < count; i++) {
+    String ip, user_id
+    if (i == 0) {
+      ip = '127.0.0.1'
+      user_id = 'kimchy'
+    } else {
+      ip = '10.42.42.42'
+      user_id= 'elkbee'
+    }
+    buildRestTests.setups[name] += """
+            { "index":{"_id": "$i"} }
+            { "@timestamp": "2099-11-15T14:12:12", "http": { "request": { "method": "get" }, "response": { "bytes": 1070000, "status_code": 200 }, "version": "1.1" }, "message": "GET /search HTTP/1.1 200 1070000", "source": { "ip": "$ip" }, "user": { "id": "$user_id" } }"""
+  }
+}
+setupMyIndex('my_index', 5)
+setupMyIndex('my_index_big', 120)
+setupMyIndex('my_index_huge', 1200)
+
 buildRestTests.setups['host'] = '''
   # Fetch the http host. We use the host of the master because we know there will always be a master.
   - do:

+ 60 - 31
docs/reference/search/search.asciidoc

@@ -8,9 +8,9 @@ Returns search hits that match the query defined in the request.
 
 [source,console]
 ----
-GET /twitter/_search
+GET /my-index-000001/_search
 ----
-// TEST[setup:twitter]
+// TEST[setup:my_index]
 
 [[search-search-api-request]]
 ==== {api-request-title}
@@ -594,9 +594,9 @@ Key is the field name. Value is the value for the field.
 
 [source,console]
 ----
-GET /twitter/_search?q=user:kimchy
+GET /my-index-000001/_search?q=user.id:kimchy
 ----
-// TEST[continued]
+// TEST[setup:my_index]
 
 The API returns the following response:
 
@@ -619,14 +619,28 @@ The API returns the following response:
     "max_score": 1.3862942,
     "hits": [
       {
-        "_index": "twitter",
+        "_index": "my-index-000001",
         "_id": "0",
         "_score": 1.3862942,
         "_source": {
-          "date": "2009-11-15T14:12:12",
-          "likes": 0,
-          "message": "trying out Elasticsearch",
-          "user": "kimchy"
+          "@timestamp": "2099-11-15T14:12:12",
+          "http": {
+            "request": {
+              "method": "get"
+            },
+            "response": {
+              "status_code": 200,
+              "bytes": 1070000
+            },
+            "version": "1.1"
+          },
+          "source": {
+            "ip": "127.0.0.1"
+          },
+          "message": "GET /search HTTP/1.1 200 1070000",
+          "user": {
+            "id": "kimchy"
+          }
         }
       }
     ]
@@ -640,9 +654,10 @@ The API returns the following response:
 
 [source,console]
 ----
-GET /kimchy,elasticsearch/_search?q=user:kimchy
+GET /my-index-000001,my-index-000002/_search?q=user.id:kimchy
 ----
-// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]
+// TEST[setup:my_index]
+// TEST[s/^/PUT my-index-000002\n/]
 
 [[search-api-all-ex]]
 ===== Search a cluster using the `q` query parameter
@@ -652,47 +667,47 @@ omit the `<target>` parameter.
 
 [source,console]
 ----
-GET /_search?q=user:kimchy
+GET /_search?q=user.id:kimchy
 ----
-// TEST[continued]
+// TEST[setup:my_index]
 
 Alternatively,
 you can use the `_all` or `*` value in the `<target>` parameter.
 
 [source,console]
 ----
-GET /_all/_search?q=user:kimchy
+GET /_all/_search?q=user.id:kimchy
 ----
-// TEST[continued]
+// TEST[setup:my_index]
 
 [source,console]
 ----
-GET /*/_search?q=user:kimchy
+GET /*/_search?q=user.id:kimchy
 ----
-// TEST[continued]
+// TEST[setup:my_index]
 
 [[search-request-body-api-example]]
 ===== Search using the `query` request body parameter
 
 [source,console]
---------------------------------------------------
-GET /twitter/_search
+----
+GET /my-index-000001/_search
 {
   "query": {
     "term": {
-      "user": "kimchy"
+      "user.id": "kimchy"
     }
   }
 }
---------------------------------------------------
-// TEST[setup:twitter]
+----
+// TEST[setup:my_index]
 
 The API returns the following response:
 
 [source,console-result]
---------------------------------------------------
+----
 {
-  "took": 1,
+  "took": 5,
   "timed_out": false,
   "_shards": {
     "total": 1,
@@ -708,18 +723,32 @@ The API returns the following response:
     "max_score": 1.3862942,
     "hits": [
       {
-        "_index": "twitter",
+        "_index": "my-index-000001",
         "_id": "0",
         "_score": 1.3862942,
         "_source": {
-          "user": "kimchy",
-          "message": "trying out Elasticsearch",
-          "date": "2009-11-15T14:12:12",
-          "likes": 0
+          "@timestamp": "2099-11-15T14:12:12",
+          "http": {
+            "request": {
+              "method": "get"
+            },
+            "response": {
+              "status_code": 200,
+              "bytes": 1070000
+            },
+            "version": "1.1"
+          },
+          "source": {
+            "ip": "127.0.0.1"
+          },
+          "message": "GET /search HTTP/1.1 200 1070000",
+          "user": {
+            "id": "kimchy"
+          }
         }
       }
     ]
   }
 }
---------------------------------------------------
-// TESTRESPONSE[s/"took": 1/"took": $body.took/]
+----
+// TESTRESPONSE[s/"took": 5/"took": $body.took/]