Skip to content

Commit f8329db

Browse files
committed
Adding get random sample API
1 parent 53b2e21 commit f8329db

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { RequestBase } from '@_types/Base'
21+
22+
/**
23+
* Request for a random sample of raw documents ingested into the given index or data stream.
24+
*
25+
* @rest_spec_name indices.get_sample
26+
* @availability stack since=9.3.0 stability=experimental
27+
* @doc_id random_sample
28+
* @doc_tag random_sample
29+
*/
30+
export interface Request extends RequestBase {
31+
urls: [
32+
{
33+
path: '{index}/_data_stream'
34+
methods: ['GET']
35+
}
36+
]
37+
path_parts: {
38+
/**
39+
* Single index or data stream name. Wildcards are not supported.
40+
*/
41+
index: string
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { RawDocument } from './_types/RawDocument'
21+
22+
/**
23+
* Response type for the get_random_samples API.
24+
* It reuses the standard SearchResponse structure.
25+
*/
26+
export class Response {
27+
body: { sample: RawDocument[] }
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Indices } from '@_types/common'
21+
22+
export class RawDocument {
23+
/**
24+
* Name of the index for this raw document.
25+
*/
26+
index: string
27+
/**
28+
* The original raw source.
29+
*/
30+
source: Index
31+
}
32+
33+
export class Index {
34+
index: Indices
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# summary: ''
2+
description: A successful response for retrieving the random sample for an index or data stream.
3+
# type: response
4+
# response_code: 200
5+
value: |-
6+
{
7+
"sample": [
8+
{
9+
"index": "logs",
10+
"source": {
11+
"@timestamp": "2099-11-15T13:12:00",
12+
"message": "Node 0 message",
13+
"user": {
14+
"id": "kimchy"
15+
},
16+
"network": {
17+
"name": "Guest"
18+
}
19+
}
20+
},
21+
{
22+
"index": "logs",
23+
"source": {
24+
"@timestamp": "2079-11-15T13:12:00",
25+
"message": "Node 1 message",
26+
"user": {
27+
"id": "kimchy"
28+
},
29+
"network": {
30+
"name": "Guest"
31+
}
32+
}
33+
}
34+
]
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
method_request: GET /my-index-000001/_sample

0 commit comments

Comments
 (0)