Skip to content

Commit 3113f94

Browse files
authored
[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.
1 parent 80b674f commit 3113f94

File tree

2 files changed

+103
-31
lines changed

2 files changed

+103
-31
lines changed

docs/build.gradle

+43
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,49 @@ setupTwitter('twitter', 5)
167167
setupTwitter('big_twitter', 120)
168168
setupTwitter('huge_twitter', 1200)
169169

170+
Closure setupMyIndex = { String name, int count ->
171+
buildRestTests.setups[name] = '''
172+
- do:
173+
indices.create:
174+
index: my-index-000001
175+
body:
176+
settings:
177+
number_of_shards: 1
178+
number_of_replicas: 1
179+
mappings:
180+
properties:
181+
"@timestamp":
182+
type: date
183+
message:
184+
type: text
185+
user:
186+
properties:
187+
id:
188+
type: keyword
189+
doc_values: true
190+
- do:
191+
bulk:
192+
index: my-index-000001
193+
refresh: true
194+
body: |'''
195+
for (int i = 0; i < count; i++) {
196+
String ip, user_id
197+
if (i == 0) {
198+
ip = '127.0.0.1'
199+
user_id = 'kimchy'
200+
} else {
201+
ip = '10.42.42.42'
202+
user_id= 'elkbee'
203+
}
204+
buildRestTests.setups[name] += """
205+
{ "index":{"_id": "$i"} }
206+
{ "@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" } }"""
207+
}
208+
}
209+
setupMyIndex('my_index', 5)
210+
setupMyIndex('my_index_big', 120)
211+
setupMyIndex('my_index_huge', 1200)
212+
170213
buildRestTests.setups['host'] = '''
171214
# Fetch the http host. We use the host of the master because we know there will always be a master.
172215
- do:

docs/reference/search/search.asciidoc

+60-31
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Returns search hits that match the query defined in the request.
88

99
[source,console]
1010
----
11-
GET /twitter/_search
11+
GET /my-index-000001/_search
1212
----
13-
// TEST[setup:twitter]
13+
// TEST[setup:my_index]
1414

1515
[[search-search-api-request]]
1616
==== {api-request-title}
@@ -594,9 +594,9 @@ Key is the field name. Value is the value for the field.
594594

595595
[source,console]
596596
----
597-
GET /twitter/_search?q=user:kimchy
597+
GET /my-index-000001/_search?q=user.id:kimchy
598598
----
599-
// TEST[continued]
599+
// TEST[setup:my_index]
600600

601601
The API returns the following response:
602602

@@ -619,14 +619,28 @@ The API returns the following response:
619619
"max_score": 1.3862942,
620620
"hits": [
621621
{
622-
"_index": "twitter",
622+
"_index": "my-index-000001",
623623
"_id": "0",
624624
"_score": 1.3862942,
625625
"_source": {
626-
"date": "2009-11-15T14:12:12",
627-
"likes": 0,
628-
"message": "trying out Elasticsearch",
629-
"user": "kimchy"
626+
"@timestamp": "2099-11-15T14:12:12",
627+
"http": {
628+
"request": {
629+
"method": "get"
630+
},
631+
"response": {
632+
"status_code": 200,
633+
"bytes": 1070000
634+
},
635+
"version": "1.1"
636+
},
637+
"source": {
638+
"ip": "127.0.0.1"
639+
},
640+
"message": "GET /search HTTP/1.1 200 1070000",
641+
"user": {
642+
"id": "kimchy"
643+
}
630644
}
631645
}
632646
]
@@ -640,9 +654,10 @@ The API returns the following response:
640654

641655
[source,console]
642656
----
643-
GET /kimchy,elasticsearch/_search?q=user:kimchy
657+
GET /my-index-000001,my-index-000002/_search?q=user.id:kimchy
644658
----
645-
// TEST[s/^/PUT kimchy\nPUT elasticsearch\n/]
659+
// TEST[setup:my_index]
660+
// TEST[s/^/PUT my-index-000002\n/]
646661

647662
[[search-api-all-ex]]
648663
===== Search a cluster using the `q` query parameter
@@ -652,47 +667,47 @@ omit the `<target>` parameter.
652667

653668
[source,console]
654669
----
655-
GET /_search?q=user:kimchy
670+
GET /_search?q=user.id:kimchy
656671
----
657-
// TEST[continued]
672+
// TEST[setup:my_index]
658673

659674
Alternatively,
660675
you can use the `_all` or `*` value in the `<target>` parameter.
661676

662677
[source,console]
663678
----
664-
GET /_all/_search?q=user:kimchy
679+
GET /_all/_search?q=user.id:kimchy
665680
----
666-
// TEST[continued]
681+
// TEST[setup:my_index]
667682

668683
[source,console]
669684
----
670-
GET /*/_search?q=user:kimchy
685+
GET /*/_search?q=user.id:kimchy
671686
----
672-
// TEST[continued]
687+
// TEST[setup:my_index]
673688

674689
[[search-request-body-api-example]]
675690
===== Search using the `query` request body parameter
676691

677692
[source,console]
678-
--------------------------------------------------
679-
GET /twitter/_search
693+
----
694+
GET /my-index-000001/_search
680695
{
681696
"query": {
682697
"term": {
683-
"user": "kimchy"
698+
"user.id": "kimchy"
684699
}
685700
}
686701
}
687-
--------------------------------------------------
688-
// TEST[setup:twitter]
702+
----
703+
// TEST[setup:my_index]
689704

690705
The API returns the following response:
691706

692707
[source,console-result]
693-
--------------------------------------------------
708+
----
694709
{
695-
"took": 1,
710+
"took": 5,
696711
"timed_out": false,
697712
"_shards": {
698713
"total": 1,
@@ -708,18 +723,32 @@ The API returns the following response:
708723
"max_score": 1.3862942,
709724
"hits": [
710725
{
711-
"_index": "twitter",
726+
"_index": "my-index-000001",
712727
"_id": "0",
713728
"_score": 1.3862942,
714729
"_source": {
715-
"user": "kimchy",
716-
"message": "trying out Elasticsearch",
717-
"date": "2009-11-15T14:12:12",
718-
"likes": 0
730+
"@timestamp": "2099-11-15T14:12:12",
731+
"http": {
732+
"request": {
733+
"method": "get"
734+
},
735+
"response": {
736+
"status_code": 200,
737+
"bytes": 1070000
738+
},
739+
"version": "1.1"
740+
},
741+
"source": {
742+
"ip": "127.0.0.1"
743+
},
744+
"message": "GET /search HTTP/1.1 200 1070000",
745+
"user": {
746+
"id": "kimchy"
747+
}
719748
}
720749
}
721750
]
722751
}
723752
}
724-
--------------------------------------------------
725-
// TESTRESPONSE[s/"took": 1/"took": $body.took/]
753+
----
754+
// TESTRESPONSE[s/"took": 5/"took": $body.took/]

0 commit comments

Comments
 (0)