Skip to content

Commit 331a817

Browse files
committed
[API] Adds text_structure APIS find_field_structure and find_message_structure
1 parent 8990beb commit 331a817

File tree

5 files changed

+199
-1
lines changed

5 files changed

+199
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module TextStructure
24+
module Actions
25+
# Finds the structure of a text field in an index.
26+
#
27+
# @option arguments [String] :index The index containing the analyzed field (*Required*)
28+
# @option arguments [String] :field The field that should be analyzed (*Required*)
29+
# @option arguments [Integer] :documents_to_sample How many documents should be included in the analysis
30+
# @option arguments [Time] :timeout Timeout after which the analysis will be aborted
31+
# @option arguments [String] :format Optional parameter to specify the high level file format (options: ndjson, xml, delimited, semi_structured_text)
32+
# @option arguments [List] :column_names Optional parameter containing a comma separated list of the column names for a delimited file
33+
# @option arguments [String] :delimiter Optional parameter to specify the delimiter character for a delimited file - must be a single character
34+
# @option arguments [String] :quote Optional parameter to specify the quote character for a delimited file - must be a single character
35+
# @option arguments [Boolean] :should_trim_fields Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them
36+
# @option arguments [String] :grok_pattern Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file
37+
# @option arguments [String] :ecs_compatibility Optional parameter to specify the compatibility mode with ECS Grok patterns - may be either 'v1' or 'disabled'
38+
# @option arguments [String] :timestamp_field Optional parameter to specify the timestamp field in the file
39+
# @option arguments [String] :timestamp_format Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format
40+
# @option arguments [Boolean] :explain Whether to include a commentary on how the structure was derived
41+
# @option arguments [Hash] :headers Custom HTTP headers
42+
#
43+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/find-field-structure.html
44+
#
45+
def find_field_structure(arguments = {})
46+
request_opts = { endpoint: arguments[:endpoint] || 'text_structure.find_field_structure' }
47+
48+
arguments = arguments.clone
49+
headers = arguments.delete(:headers) || {}
50+
51+
body = nil
52+
53+
method = Elasticsearch::API::HTTP_GET
54+
path = '_text_structure/find_field_structure'
55+
params = Utils.process_params(arguments)
56+
57+
Elasticsearch::API::Response.new(
58+
perform_request(method, path, params, body, headers, request_opts)
59+
)
60+
end
61+
end
62+
end
63+
end
64+
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module TextStructure
24+
module Actions
25+
# Finds the structure of a list of messages. The messages must contain data that is suitable to be ingested into Elasticsearch.
26+
#
27+
# @option arguments [Time] :timeout Timeout after which the analysis will be aborted
28+
# @option arguments [String] :format Optional parameter to specify the high level file format (options: ndjson, xml, delimited, semi_structured_text)
29+
# @option arguments [List] :column_names Optional parameter containing a comma separated list of the column names for a delimited file
30+
# @option arguments [String] :delimiter Optional parameter to specify the delimiter character for a delimited file - must be a single character
31+
# @option arguments [String] :quote Optional parameter to specify the quote character for a delimited file - must be a single character
32+
# @option arguments [Boolean] :should_trim_fields Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them
33+
# @option arguments [String] :grok_pattern Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file
34+
# @option arguments [String] :ecs_compatibility Optional parameter to specify the compatibility mode with ECS Grok patterns - may be either 'v1' or 'disabled'
35+
# @option arguments [String] :timestamp_field Optional parameter to specify the timestamp field in the file
36+
# @option arguments [String] :timestamp_format Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format
37+
# @option arguments [Boolean] :explain Whether to include a commentary on how the structure was derived
38+
# @option arguments [Hash] :headers Custom HTTP headers
39+
# @option arguments [Hash] :body JSON object with one field [messages], containing an array of messages to be analyzed (*Required*)
40+
#
41+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/find-message-structure.html
42+
#
43+
def find_message_structure(arguments = {})
44+
request_opts = { endpoint: arguments[:endpoint] || 'text_structure.find_message_structure' }
45+
46+
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
47+
48+
arguments = arguments.clone
49+
headers = arguments.delete(:headers) || {}
50+
51+
body = arguments.delete(:body)
52+
53+
method = Elasticsearch::API::HTTP_POST
54+
path = '_text_structure/find_message_structure'
55+
params = Utils.process_params(arguments)
56+
57+
Elasticsearch::API::Response.new(
58+
perform_request(method, path, params, body, headers, request_opts)
59+
)
60+
end
61+
end
62+
end
63+
end
64+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.text_structure#test_grok_pattern' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'_text_structure/find_field_structure',
25+
{},
26+
nil,
27+
{},
28+
{ endpoint: 'text_structure.find_field_structure' }
29+
]
30+
end
31+
32+
it 'performs the request' do
33+
expect(client_double.text_structure.find_field_structure).to be_a Elasticsearch::API::Response
34+
end
35+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.text_structure#test_grok_pattern' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_text_structure/find_message_structure',
25+
{},
26+
{},
27+
{},
28+
{ endpoint: 'text_structure.find_message_structure' }
29+
]
30+
end
31+
32+
it 'performs the request' do
33+
expect(client_double.text_structure.find_message_structure(body: {})).to be_a Elasticsearch::API::Response
34+
end
35+
end

elasticsearch-api/spec/elasticsearch/api/actions/text_structure/find_structure_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'_text_structure/find_structure',
2525
{},
2626
{},
27-
{"Content-Type"=>"application/x-ndjson"},
27+
{ 'Content-Type' => 'application/x-ndjson' },
2828
{ endpoint: 'text_structure.find_structure' }
2929
]
3030
end

0 commit comments

Comments
 (0)