Skip to content

Commit b7e3a1e

Browse files
colleenmcginnisleemthompoMpdreamzszabosteve
authored
[docs] Migrate docs from AsciiDoc to Markdown (#123507)
* delete asciidoc files * add migrated files * fix errors * Disable docs tests * Clarify release notes page titles * Revert "Clarify release notes page titles" This reverts commit 8be6886. * Comment out edternal URI images * Clean up query languages landing pages, link to conceptual docs * Add .md to url * Fixes inference processor nesting. --------- Co-authored-by: Liam Thompson <[email protected]> Co-authored-by: Liam Thompson <[email protected]> Co-authored-by: Martijn Laarman <[email protected]> Co-authored-by: István Zoltán Szabó <[email protected]>
1 parent 2113a3c commit b7e3a1e

File tree

4,082 files changed

+141513
-376367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,082 files changed

+141513
-376367
lines changed

docs/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ext.docsFileTree = fileTree(projectDir) {
3737
}
3838

3939
tasks.named("yamlRestTest") {
40+
enabled = false
4041
if (buildParams.isSnapshotBuild() == false) {
4142
// LOOKUP is not available in snapshots
4243
systemProperty 'tests.rest.blacklist', [
@@ -47,6 +48,7 @@ tasks.named("yamlRestTest") {
4748

4849
/* List of files that have snippets that will not work until platinum tests can occur ... */
4950
tasks.named("buildRestTests").configure {
51+
enabled = false
5052
getExpectedUnconvertedCandidates().addAll(
5153
'reference/ml/anomaly-detection/ml-configuring-transform.asciidoc',
5254
'reference/ml/anomaly-detection/apis/delete-calendar-event.asciidoc',

docs/docset.yml

Lines changed: 506 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/plugins/current/creating-classic-plugins.html
4+
---
5+
6+
# Creating classic plugins [creating-classic-plugins]
7+
8+
Classic plugins provide {{es}} with mechanisms for custom authentication, authorization, scoring, and more.
9+
10+
::::{admonition} Plugin release lifecycle
11+
:class: important
12+
13+
Classic plugins require you to build a new version for each new {{es}} release. This version is checked when the plugin is installed and when it is loaded. {{es}} will refuse to start in the presence of plugins with the incorrect `elasticsearch.version`.
14+
15+
::::
16+
17+
18+
19+
## Classic plugin file structure [_classic_plugin_file_structure]
20+
21+
Classic plugins are ZIP files composed of JAR files and [a metadata file called `plugin-descriptor.properties`](/extend/plugin-descriptor-file-classic.md), a Java properties file that describes the plugin.
22+
23+
Note that only JAR files at the root of the plugin are added to the classpath for the plugin. If you need other resources, package them into a resources JAR.
24+
25+
26+
## Example plugins [_example_plugins]
27+
28+
The {{es}} repository contains [examples of plugins](https://github.com/elastic/elasticsearch/tree/main/plugins/examples). Some of these include:
29+
30+
* a plugin with [custom settings](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/custom-settings)
31+
* a plugin with a [custom ingest processor](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/custom-processor)
32+
* adding [custom rest endpoints](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/rest-handler)
33+
* adding a [custom rescorer](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/rescore)
34+
* a script [implemented in Java](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/script-expert-scoring)
35+
36+
These examples provide the bare bones needed to get started. For more information about how to write a plugin, we recommend looking at the [source code of existing plugins](https://github.com/elastic/elasticsearch/tree/main/plugins/) for inspiration.
37+
38+
39+
## Testing your plugin [_testing_your_plugin]
40+
41+
Use `bin/elasticsearch-plugin install file:///path/to/your/plugin` to install your plugin for testing. The Java plugin is auto-loaded only if it’s in the `plugins/` directory.
42+
43+
44+
## Java Security permissions [plugin-authors-jsm]
45+
46+
Some plugins may need additional security permissions. A plugin can include the optional `plugin-security.policy` file containing `grant` statements for additional permissions. Any additional permissions will be displayed to the user with a large warning, and they will have to confirm them when installing the plugin interactively. So if possible, it is best to avoid requesting any spurious permissions!
47+
48+
If you are using the {{es}} Gradle build system, place this file in `src/main/plugin-metadata` and it will be applied during unit tests as well.
49+
50+
The Java security model is stack-based, and additional permissions are granted to the jars in your plugin, so you have to write proper security code around operations requiring elevated privileges. You might add a check to prevent unprivileged code (such as scripts) from gaining escalated permissions. For example:
51+
52+
```java
53+
// ES permission you should check before doPrivileged() blocks
54+
import org.elasticsearch.SpecialPermission;
55+
56+
SecurityManager sm = System.getSecurityManager();
57+
if (sm != null) {
58+
// unprivileged code such as scripts do not have SpecialPermission
59+
sm.checkPermission(new SpecialPermission());
60+
}
61+
AccessController.doPrivileged(
62+
// sensitive operation
63+
);
64+
```
65+
66+
Check [Secure Coding Guidelines for Java SE](https://www.oracle.com/technetwork/java/seccodeguide-139067.md) for more information.
67+
68+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/plugins/current/creating-stable-plugins.html
4+
---
5+
6+
# Creating text analysis plugins with the stable plugin API [creating-stable-plugins]
7+
8+
Text analysis plugins provide {{es}} with custom [Lucene analyzers, token filters, character filters, and tokenizers](docs-content://manage-data/data-store/text-analysis.md).
9+
10+
11+
## The stable plugin API [_the_stable_plugin_api]
12+
13+
Text analysis plugins can be developed against the stable plugin API. This API consists of the following dependencies:
14+
15+
* `plugin-api` - an API used by plugin developers to implement custom {{es}} plugins.
16+
* `plugin-analysis-api` - an API used by plugin developers to implement analysis plugins and integrate them into {{es}}.
17+
* `lucene-analysis-common` - a dependency of `plugin-analysis-api` that contains core Lucene analysis interfaces like `Tokenizer`, `Analyzer`, and `TokenStream`.
18+
19+
For new versions of {{es}} within the same major version, plugins built against this API does not need to be recompiled. Future versions of the API will be backwards compatible and plugins are binary compatible with future versions of {{es}}. In other words, once you have a working artifact, you can re-use it when you upgrade {{es}} to a new bugfix or minor version.
20+
21+
A text analysis plugin can implement four factory classes that are provided by the analysis plugin API.
22+
23+
* `AnalyzerFactory` to create a Lucene analyzer
24+
* `CharFilterFactory` to create a character character filter
25+
* `TokenFilterFactory` to create a Lucene token filter
26+
* `TokenizerFactory` to create a Lucene tokenizer
27+
28+
The key to implementing a stable plugin is the `@NamedComponent` annotation. Many of {{es}}'s components have names that are used in configurations. For example, the keyword analyzer is referenced in configuration with the name `"keyword"`. Once your custom plugin is installed in your cluster, your named components may be referenced by name in these configurations as well.
29+
30+
You can also create text analysis plugins as a [classic plugin](/extend/creating-classic-plugins.md). However, classic plugins are pinned to a specific version of {{es}}. You need to recompile them when upgrading {{es}}. Because classic plugins are built against internal APIs that can change, upgrading to a new version may require code changes.
31+
32+
33+
## Stable plugin file structure [_stable_plugin_file_structure]
34+
35+
Stable plugins are ZIP files composed of JAR files and two metadata files:
36+
37+
* `stable-plugin-descriptor.properties` - a Java properties file that describes the plugin. Refer to [The plugin descriptor file for stable plugins](/extend/plugin-descriptor-file-stable.md).
38+
* `named_components.json` - a JSON file mapping interfaces to key-value pairs of component names and implementation classes.
39+
40+
Note that only JAR files at the root of the plugin are added to the classpath for the plugin. If you need other resources, package them into a resources JAR.
41+
42+
43+
## Development process [_development_process]
44+
45+
Elastic provides a Gradle plugin, `elasticsearch.stable-esplugin`, that makes it easier to develop and package stable plugins. The steps in this section assume you use this plugin. However, you don’t need Gradle to create plugins.
46+
47+
The {{es}} Github repository contains [an example analysis plugin](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/stable-analysis). The example `build.gradle` build script provides a good starting point for developing your own plugin.
48+
49+
50+
### Prerequisites [_prerequisites]
51+
52+
Plugins are written in Java, so you need to install a Java Development Kit (JDK). Install Gradle if you want to use Gradle.
53+
54+
55+
### Step by step [_step_by_step]
56+
57+
1. Create a directory for your project.
58+
2. Copy the example `build.gradle` build script to your project directory. Note that this build script uses the `elasticsearch.stable-esplugin` gradle plugin to build your plugin.
59+
3. Edit the `build.gradle` build script:
60+
61+
* Add a definition for the `pluginApiVersion` and matching `luceneVersion` variables to the top of the file. You can find these versions in the `build-tools-internal/version.properties` file in the [Elasticsearch Github repository](https://github.com/elastic/elasticsearch/).
62+
* Edit the `name` and `description` in the `esplugin` section of the build script. This will create the plugin descriptor file. If you’re not using the `elasticsearch.stable-esplugin` gradle plugin, refer to [The plugin descriptor file for stable plugins](/extend/plugin-descriptor-file-stable.md) to create the file manually.
63+
* Add module information.
64+
* Ensure you have declared the following compile-time dependencies. These dependencies are compile-time only because {{es}} will provide these libraries at runtime.
65+
66+
* `org.elasticsearch.plugin:elasticsearch-plugin-api`
67+
* `org.elasticsearch.plugin:elasticsearch-plugin-analysis-api`
68+
* `org.apache.lucene:lucene-analysis-common`
69+
70+
* For unit testing, ensure these dependencies have also been added to the `build.gradle` script as `testImplementation` dependencies.
71+
72+
4. Implement an interface from the analysis plugin API, annotating it with `NamedComponent`. Refer to [Example text analysis plugin](/extend/example-text-analysis-plugin.md) for an example.
73+
5. You should now be able to assemble a plugin ZIP file by running:
74+
75+
```sh
76+
gradle bundlePlugin
77+
```
78+
79+
The resulting plugin ZIP file is written to the `build/distributions` directory.
80+
81+
82+
83+
### YAML REST tests [_yaml_rest_tests]
84+
85+
The Gradle `elasticsearch.yaml-rest-test` plugin enables testing of your plugin using the [{{es}} yamlRestTest framework](https://github.com/elastic/elasticsearch/blob/main/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc). These tests use a YAML-formatted domain language to issue REST requests against an internal {{es}} cluster that has your plugin installed, and to check the results of those requests. The structure of a YAML REST test directory is as follows:
86+
87+
* A test suite class, defined under `src/yamlRestTest/java`. This class should extend `ESClientYamlSuiteTestCase`.
88+
* The YAML tests themselves should be defined under `src/yamlRestTest/resources/test/`.
89+
90+
91+
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/plugins/current/example-text-analysis-plugin.html
4+
---
5+
6+
# Example text analysis plugin [example-text-analysis-plugin]
7+
8+
This example shows how to create a simple "Hello world" text analysis plugin using the stable plugin API. The plugin provides a custom Lucene token filter that strips all tokens except for "hello" and "world".
9+
10+
Elastic provides a Grade plugin, `elasticsearch.stable-esplugin`, that makes it easier to develop and package stable plugins. The steps in this guide assume you use this plugin. However, you don’t need Gradle to create plugins.
11+
12+
1. Create a new directory for your project.
13+
2. In this example, the source code is organized under the `main` and `test` directories. In your project’s home directory, create `src/` `src/main/`, and `src/test/` directories.
14+
3. Create the following `build.gradle` build script in your project’s home directory:
15+
16+
```gradle
17+
ext.pluginApiVersion = '8.7.0'
18+
ext.luceneVersion = '9.5.0'
19+
20+
buildscript {
21+
ext.pluginApiVersion = '8.7.0'
22+
repositories {
23+
mavenCentral()
24+
}
25+
dependencies {
26+
classpath "org.elasticsearch.gradle:build-tools:${pluginApiVersion}"
27+
}
28+
}
29+
30+
apply plugin: 'elasticsearch.stable-esplugin'
31+
apply plugin: 'elasticsearch.yaml-rest-test'
32+
33+
esplugin {
34+
name 'my-plugin'
35+
description 'My analysis plugin'
36+
}
37+
38+
group 'org.example'
39+
version '1.0-SNAPSHOT'
40+
41+
repositories {
42+
mavenLocal()
43+
mavenCentral()
44+
}
45+
46+
dependencies {
47+
48+
//TODO transitive dependency off and plugin-api dependency?
49+
compileOnly "org.elasticsearch.plugin:elasticsearch-plugin-api:${pluginApiVersion}"
50+
compileOnly "org.elasticsearch.plugin:elasticsearch-plugin-analysis-api:${pluginApiVersion}"
51+
compileOnly "org.apache.lucene:lucene-analysis-common:${luceneVersion}"
52+
53+
//TODO for testing this also have to be declared
54+
testImplementation "org.elasticsearch.plugin:elasticsearch-plugin-api:${pluginApiVersion}"
55+
testImplementation "org.elasticsearch.plugin:elasticsearch-plugin-analysis-api:${pluginApiVersion}"
56+
testImplementation "org.apache.lucene:lucene-analysis-common:${luceneVersion}"
57+
58+
testImplementation ('junit:junit:4.13.2'){
59+
exclude group: 'org.hamcrest'
60+
}
61+
testImplementation 'org.mockito:mockito-core:4.4.0'
62+
testImplementation 'org.hamcrest:hamcrest:2.2'
63+
64+
}
65+
```
66+
67+
4. In `src/main/java/org/example/`, create `HelloWorldTokenFilter.java`. This file provides the code for a token filter that strips all tokens except for "hello" and "world":
68+
69+
```java
70+
package org.example;
71+
72+
import org.apache.lucene.analysis.FilteringTokenFilter;
73+
import org.apache.lucene.analysis.TokenStream;
74+
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
75+
76+
import java.util.Arrays;
77+
78+
public class HelloWorldTokenFilter extends FilteringTokenFilter {
79+
private final CharTermAttribute term = addAttribute(CharTermAttribute.class);
80+
81+
public HelloWorldTokenFilter(TokenStream input) {
82+
super(input);
83+
}
84+
85+
@Override
86+
public boolean accept() {
87+
if (term.length() != 5) return false;
88+
return Arrays.equals(term.buffer(), 0, 4, "hello".toCharArray(), 0, 4)
89+
|| Arrays.equals(term.buffer(), 0, 4, "world".toCharArray(), 0, 4);
90+
}
91+
}
92+
```
93+
94+
5. This filter can be provided to Elasticsearch using the following `HelloWorldTokenFilterFactory.java` factory class. The `@NamedComponent` annotation is used to give the filter the `hello_world` name. This is the name you can use to refer to the filter, once the plugin has been deployed.
95+
96+
```java
97+
package org.example;
98+
99+
import org.apache.lucene.analysis.TokenStream;
100+
import org.elasticsearch.plugin.analysis.TokenFilterFactory;
101+
import org.elasticsearch.plugin.NamedComponent;
102+
103+
@NamedComponent(value = "hello_world")
104+
public class HelloWorldTokenFilterFactory implements TokenFilterFactory {
105+
106+
@Override
107+
public TokenStream create(TokenStream tokenStream) {
108+
return new HelloWorldTokenFilter(tokenStream);
109+
}
110+
111+
}
112+
```
113+
114+
6. Unit tests may go under the `src/test` directory. You will have to add dependencies for your preferred testing framework.
115+
7. Run:
116+
117+
```sh
118+
gradle bundlePlugin
119+
```
120+
121+
This builds the JAR file, generates the metadata files, and bundles them into a plugin ZIP file. The resulting ZIP file will be written to the `build/distributions` directory.
122+
123+
8. [Install the plugin](/reference/elasticsearch-plugins/plugin-management.md).
124+
9. You can use the `_analyze` API to verify that the `hello_world` token filter works as expected:
125+
126+
```console
127+
GET /_analyze
128+
{
129+
"text": "hello to everyone except the world",
130+
"tokenizer": "standard",
131+
"filter": ["hello_world"]
132+
}
133+
```
134+
135+
136+
137+
## YAML REST tests [_yaml_rest_tests_2]
138+
139+
If you are using the `elasticsearch.stable-esplugin` plugin for Gradle, you can use {{es}}'s YAML Rest Test framework. This framework allows you to load your plugin in a running test cluster and issue real REST API queries against it. The full syntax for this framework is beyond the scope of this tutorial, but there are many examples in the Elasticsearch repository. Refer to the [example analysis plugin](https://github.com/elastic/elasticsearch/tree/main/plugins/examples/stable-analysis) in the {{es}} Github repository for an example.
140+
141+
1. Create a `yamlRestTest` directory in the `src` directory.
142+
2. Under the `yamlRestTest` directory, create a `java` folder for Java sources and a `resources` folder.
143+
3. In `src/yamlRestTest/java/org/example/`, create `HelloWorldPluginClientYamlTestSuiteIT.java`. This class implements `ESClientYamlSuiteTestCase`.
144+
145+
```java
146+
import com.carrotsearch.randomizedtesting.annotations.Name;
147+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
148+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
149+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
150+
151+
public class HelloWorldPluginClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
152+
153+
public HelloWorldPluginClientYamlTestSuiteIT(
154+
@Name("yaml") ClientYamlTestCandidate testCandidate
155+
) {
156+
super(testCandidate);
157+
}
158+
159+
@ParametersFactory
160+
public static Iterable<Object[]> parameters() throws Exception {
161+
return ESClientYamlSuiteTestCase.createParameters();
162+
}
163+
}
164+
```
165+
166+
4. In `src/yamlRestTest/resources/rest-api-spec/test/plugin`, create the `10_token_filter.yml` YAML file:
167+
168+
```yaml
169+
## Sample rest test
170+
---
171+
"Hello world plugin test - removes all tokens except hello and world":
172+
- do:
173+
indices.analyze:
174+
body:
175+
text: hello to everyone except the world
176+
tokenizer: standard
177+
filter:
178+
- type: "hello_world"
179+
- length: { tokens: 2 }
180+
- match: { tokens.0.token: "hello" }
181+
- match: { tokens.1.token: "world" }
182+
```
183+
184+
5. Run the test with:
185+
186+
```sh
187+
gradle yamlRestTest
188+
```
189+
190+

docs/extend/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html
4+
---
5+
6+
# Create Elasticsearch plugins [plugin-authors]
7+
8+
{{es}} plugins are modular bits of code that add functionality to {{es}}. Plugins are written in Java and implement Java interfaces that are defined in the source code. Plugins are composed of JAR files and metadata files, compressed in a single zip file.
9+
10+
There are two ways to create a plugin:
11+
12+
[Creating text analysis plugins with the stable plugin API](/extend/creating-stable-plugins.md)
13+
: Text analysis plugins can be developed against the stable plugin API to provide {{es}} with custom Lucene analyzers, token filters, character filters, and tokenizers.
14+
15+
[Creating classic plugins](/extend/creating-classic-plugins.md)
16+
: Other plugins can be developed against the classic plugin API to provide custom authentication, authorization, or scoring mechanisms, and more.
17+
18+
19+

0 commit comments

Comments
 (0)