Merge branch 'master' into index-lifecycle
This commit is contained in:
commit
9ee492a3f0
|
@ -31,6 +31,9 @@ Vagrant.configure(2) do |config|
|
|||
# Give the box more memory and cpu because our tests are beasts!
|
||||
vbox.memory = Integer(ENV['VAGRANT_MEMORY'] || 8192)
|
||||
vbox.cpus = Integer(ENV['VAGRANT_CPUS'] || 4)
|
||||
|
||||
# see https://github.com/hashicorp/vagrant/issues/9524
|
||||
vbox.customize ["modifyvm", :id, "--audio", "none"]
|
||||
end
|
||||
|
||||
# Switch the default share for the project root from /vagrant to
|
||||
|
|
13
build.gradle
13
build.gradle
|
@ -205,9 +205,9 @@ subprojects {
|
|||
"org.elasticsearch.gradle:build-tools:${version}": ':build-tools',
|
||||
"org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
|
||||
"org.elasticsearch:elasticsearch:${version}": ':server',
|
||||
"org.elasticsearch:elasticsearch-cli:${version}": ':server:cli',
|
||||
"org.elasticsearch:elasticsearch-core:${version}": ':libs:elasticsearch-core',
|
||||
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:elasticsearch-nio',
|
||||
"org.elasticsearch:elasticsearch-cli:${version}": ':libs:cli',
|
||||
"org.elasticsearch:elasticsearch-core:${version}": ':libs:core',
|
||||
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:nio',
|
||||
"org.elasticsearch:elasticsearch-x-content:${version}": ':libs:x-content',
|
||||
"org.elasticsearch:elasticsearch-secure-sm:${version}": ':libs:secure-sm',
|
||||
"org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
|
||||
|
@ -543,7 +543,7 @@ subprojects { project ->
|
|||
}
|
||||
}
|
||||
|
||||
/* Remove assemble on all qa projects because we don't need to publish
|
||||
/* Remove assemble/dependenciesInfo on all qa projects because we don't need to publish
|
||||
* artifacts for them. */
|
||||
gradle.projectsEvaluated {
|
||||
subprojects {
|
||||
|
@ -553,6 +553,11 @@ gradle.projectsEvaluated {
|
|||
project.tasks.remove(assemble)
|
||||
project.build.dependsOn.remove('assemble')
|
||||
}
|
||||
Task dependenciesInfo = project.tasks.findByName('dependenciesInfo')
|
||||
if (dependenciesInfo) {
|
||||
project.tasks.remove(dependenciesInfo)
|
||||
project.precommit.dependsOn.remove('dependenciesInfo')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -762,6 +762,10 @@ class BuildPlugin implements Plugin<Project> {
|
|||
|
||||
private static configureDependenciesInfo(Project project) {
|
||||
Task deps = project.tasks.create("dependenciesInfo", DependenciesInfoTask.class)
|
||||
deps.dependencies = project.configurations.compile.allDependencies
|
||||
deps.runtimeConfiguration = project.configurations.runtime
|
||||
deps.compileOnlyConfiguration = project.configurations.compileOnly
|
||||
project.afterEvaluate {
|
||||
deps.mappings = project.dependencyLicenses.mappings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,19 @@
|
|||
|
||||
package org.elasticsearch.gradle
|
||||
|
||||
import org.elasticsearch.gradle.precommit.DependencyLicensesTask
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.artifacts.DependencyResolutionListener
|
||||
import org.gradle.api.artifacts.DependencySet
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* A task to gather information about the dependencies and export them into a csv file.
|
||||
|
@ -44,7 +49,14 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
|
||||
/** Dependencies to gather information from. */
|
||||
@Input
|
||||
public DependencySet dependencies
|
||||
public Configuration runtimeConfiguration
|
||||
|
||||
/** We subtract compile-only dependencies. */
|
||||
@Input
|
||||
public Configuration compileOnlyConfiguration
|
||||
|
||||
@Input
|
||||
public LinkedHashMap<String, String> mappings
|
||||
|
||||
/** Directory to read license files */
|
||||
@InputDirectory
|
||||
|
@ -59,15 +71,34 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
|
||||
@TaskAction
|
||||
public void generateDependenciesInfo() {
|
||||
|
||||
final DependencySet runtimeDependencies = runtimeConfiguration.getAllDependencies()
|
||||
// we have to resolve the transitive dependencies and create a group:artifactId:version map
|
||||
final Set<String> compileOnlyArtifacts =
|
||||
compileOnlyConfiguration
|
||||
.getResolvedConfiguration()
|
||||
.resolvedArtifacts
|
||||
.collect { it -> "${it.moduleVersion.id.group}:${it.moduleVersion.id.name}:${it.moduleVersion.id.version}" }
|
||||
|
||||
final StringBuilder output = new StringBuilder()
|
||||
|
||||
for (Dependency dependency : dependencies) {
|
||||
// Only external dependencies are checked
|
||||
if (dependency.group != null && dependency.group.contains("elasticsearch") == false) {
|
||||
final String url = createURL(dependency.group, dependency.name, dependency.version)
|
||||
final String licenseType = getLicenseType(dependency.group, dependency.name)
|
||||
output.append("${dependency.group}:${dependency.name},${dependency.version},${url},${licenseType}\n")
|
||||
for (final Dependency dependency : runtimeDependencies) {
|
||||
// we do not need compile-only dependencies here
|
||||
if (compileOnlyArtifacts.contains("${dependency.group}:${dependency.name}:${dependency.version}")) {
|
||||
continue
|
||||
}
|
||||
// only external dependencies are checked
|
||||
if (dependency.group != null && dependency.group.contains("org.elasticsearch")) {
|
||||
continue
|
||||
}
|
||||
|
||||
final String url = createURL(dependency.group, dependency.name, dependency.version)
|
||||
final String dependencyName = DependencyLicensesTask.getDependencyName(mappings, dependency.name)
|
||||
logger.info("mapped dependency ${dependency.group}:${dependency.name} to ${dependencyName} for license info")
|
||||
|
||||
final String licenseType = getLicenseType(dependency.group, dependencyName)
|
||||
output.append("${dependency.group}:${dependency.name},${dependency.version},${url},${licenseType}\n")
|
||||
|
||||
}
|
||||
outputFile.setText(output.toString(), 'UTF-8')
|
||||
}
|
||||
|
@ -109,7 +140,8 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
}
|
||||
|
||||
if (license) {
|
||||
final String content = license.readLines("UTF-8").toString()
|
||||
// replace * because they are sometimes used at the beginning lines as if the license was a multi-line comment
|
||||
final String content = new String(license.readBytes(), "UTF-8").replaceAll("\\s+", " ").replaceAll("\\*", " ")
|
||||
final String spdx = checkSPDXLicense(content)
|
||||
if (spdx == null) {
|
||||
// License has not be identified as SPDX.
|
||||
|
@ -133,15 +165,88 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
private String checkSPDXLicense(final String licenseText) {
|
||||
String spdx = null
|
||||
|
||||
final String APACHE_2_0 = "Apache.*License.*(v|V)ersion 2.0"
|
||||
final String BSD_2 = "BSD 2-clause.*License"
|
||||
final String APACHE_2_0 = "Apache.*License.*(v|V)ersion.*2\\.0"
|
||||
|
||||
final String BSD_2 = """
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1\\. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer\\.
|
||||
2\\. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution\\.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY .+ (``|''|")AS IS(''|") AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED\\.
|
||||
IN NO EVENT SHALL .+ BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \\(INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION\\) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
\\(INCLUDING NEGLIGENCE OR OTHERWISE\\) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\\.
|
||||
""".replaceAll("\\s+", "\\\\s*")
|
||||
|
||||
final String BSD_3 = """
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
(1\\.)? Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer\\.
|
||||
(2\\.)? Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution\\.
|
||||
((3\\.)? The name of .+ may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission\\.|
|
||||
(3\\.)? Neither the name of .+ nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission\\.)
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY .+ (``|''|")AS IS(''|") AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED\\.
|
||||
IN NO EVENT SHALL .+ BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \\(INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION\\) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
\\(INCLUDING NEGLIGENCE OR OTHERWISE\\) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\\.
|
||||
""".replaceAll("\\s+", "\\\\s*")
|
||||
|
||||
final String CDDL_1_0 = "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE.*Version 1.0"
|
||||
final String CDDL_1_1 = "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE.*Version 1.1"
|
||||
final String ICU = "ICU License - ICU 1.8.1 and later"
|
||||
final String LGPL_3 = "GNU LESSER GENERAL PUBLIC LICENSE.*Version 3"
|
||||
final String MIT = "MIT License"
|
||||
|
||||
final String MIT = """
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files \\(the "Software"\\), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software\\.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\\. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE\\.
|
||||
""".replaceAll("\\s+", "\\\\s*")
|
||||
|
||||
final String MOZILLA_1_1 = "Mozilla Public License.*Version 1.1"
|
||||
|
||||
final String MOZILLA_2_0 = "Mozilla\\s*Public\\s*License\\s*Version\\s*2\\.0"
|
||||
|
||||
switch (licenseText) {
|
||||
case ~/.*${APACHE_2_0}.*/:
|
||||
spdx = 'Apache-2.0'
|
||||
|
@ -152,6 +257,9 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
case ~/.*${BSD_2}.*/:
|
||||
spdx = 'BSD-2-Clause'
|
||||
break
|
||||
case ~/.*${BSD_3}.*/:
|
||||
spdx = 'BSD-3-Clause'
|
||||
break
|
||||
case ~/.*${LGPL_3}.*/:
|
||||
spdx = 'LGPL-3.0'
|
||||
break
|
||||
|
@ -167,6 +275,9 @@ public class DependenciesInfoTask extends DefaultTask {
|
|||
case ~/.*${MOZILLA_1_1}.*/:
|
||||
spdx = 'MPL-1.1'
|
||||
break
|
||||
case ~/.*${MOZILLA_2_0}.*/:
|
||||
spdx = 'MPL-2.0'
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
|
@ -109,6 +109,10 @@ public class DependencyLicensesTask extends DefaultTask {
|
|||
mappings.put(from, to)
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> getMappings() {
|
||||
return new LinkedHashMap<>(mappings)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a rule which will skip SHA checking for the given dependency name. This should be used for
|
||||
* locally build dependencies, which cause the sha to change constantly.
|
||||
|
@ -129,10 +133,6 @@ public class DependencyLicensesTask extends DefaultTask {
|
|||
throw new GradleException("Licences dir ${licensesDir} does not exist, but there are dependencies")
|
||||
}
|
||||
|
||||
|
||||
// order is the same for keys and values iteration since we use a linked hashmap
|
||||
List<String> mapped = new ArrayList<>(mappings.values())
|
||||
Pattern mappingsPattern = Pattern.compile('(' + mappings.keySet().join(')|(') + ')')
|
||||
Map<String, Integer> licenses = new HashMap<>()
|
||||
Map<String, Integer> notices = new HashMap<>()
|
||||
Set<File> shaFiles = new HashSet<File>()
|
||||
|
@ -151,7 +151,7 @@ public class DependencyLicensesTask extends DefaultTask {
|
|||
|
||||
for (File dependency : dependencies) {
|
||||
String jarName = dependency.getName()
|
||||
String depName = jarName - ~/\-\d+.*/
|
||||
String depName = jarName - ~/\-v?\d+.*/
|
||||
if (ignoreShas.contains(depName)) {
|
||||
// local deps should not have sha files!
|
||||
if (getShaFile(jarName).exists()) {
|
||||
|
@ -162,16 +162,10 @@ public class DependencyLicensesTask extends DefaultTask {
|
|||
checkSha(dependency, jarName, shaFiles)
|
||||
}
|
||||
|
||||
logger.info("Checking license/notice for " + depName)
|
||||
Matcher match = mappingsPattern.matcher(depName)
|
||||
if (match.matches()) {
|
||||
int i = 0
|
||||
while (i < match.groupCount() && match.group(i + 1) == null) ++i;
|
||||
logger.info("Mapped dependency name ${depName} to ${mapped.get(i)} for license check")
|
||||
depName = mapped.get(i)
|
||||
}
|
||||
checkFile(depName, jarName, licenses, 'LICENSE')
|
||||
checkFile(depName, jarName, notices, 'NOTICE')
|
||||
final String dependencyName = getDependencyName(mappings, depName)
|
||||
logger.info("mapped dependency name ${depName} to ${dependencyName} for license/notice check")
|
||||
checkFile(dependencyName, jarName, licenses, 'LICENSE')
|
||||
checkFile(dependencyName, jarName, notices, 'NOTICE')
|
||||
}
|
||||
|
||||
licenses.each { license, count ->
|
||||
|
@ -189,6 +183,19 @@ public class DependencyLicensesTask extends DefaultTask {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getDependencyName(final LinkedHashMap<String, String> mappings, final String dependencyName) {
|
||||
// order is the same for keys and values iteration since we use a linked hashmap
|
||||
List<String> mapped = new ArrayList<>(mappings.values())
|
||||
Pattern mappingsPattern = Pattern.compile('(' + mappings.keySet().join(')|(') + ')')
|
||||
Matcher match = mappingsPattern.matcher(dependencyName)
|
||||
if (match.matches()) {
|
||||
int i = 0
|
||||
while (i < match.groupCount() && match.group(i + 1) == null) ++i;
|
||||
return mapped.get(i)
|
||||
}
|
||||
return dependencyName
|
||||
}
|
||||
|
||||
private File getShaFile(String jarName) {
|
||||
return new File(licensesDir, jarName + SHA_EXTENSION)
|
||||
}
|
||||
|
|
|
@ -87,8 +87,9 @@ class ClusterConfiguration {
|
|||
* A closure to call which returns the unicast host to connect to for cluster formation.
|
||||
*
|
||||
* This allows multi node clusters, or a new cluster to connect to an existing cluster.
|
||||
* The closure takes two arguments, the NodeInfo for the first node in the cluster, and
|
||||
* an AntBuilder which may be used to wait on conditions before returning.
|
||||
* The closure takes three arguments, the NodeInfo for the first node in the cluster,
|
||||
* the NodeInfo for the node current being configured, an AntBuilder which may be used
|
||||
* to wait on conditions before returning.
|
||||
*/
|
||||
@Input
|
||||
Closure unicastTransportUri = { NodeInfo seedNode, NodeInfo node, AntBuilder ant ->
|
||||
|
|
|
@ -31,6 +31,9 @@ esplugin {
|
|||
tasks.remove(assemble)
|
||||
build.dependsOn.remove('assemble')
|
||||
|
||||
dependencyLicenses.enabled = false
|
||||
dependenciesInfo.enabled = false
|
||||
|
||||
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
|
||||
|
||||
// no unit tests
|
||||
|
|
|
@ -41,11 +41,28 @@ public final class ClusterClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates cluster wide specific settings using the Cluster Update Settings API
|
||||
* Updates cluster wide specific settings using the Cluster Update Settings API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html"> Cluster Update Settings
|
||||
* API on elastic.co</a>
|
||||
* @param clusterUpdateSettingsRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public ClusterUpdateSettingsResponse putSettings(ClusterUpdateSettingsRequest clusterUpdateSettingsRequest, RequestOptions options)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings,
|
||||
options, ClusterUpdateSettingsResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates cluster wide specific settings using the Cluster Update Settings API.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html"> Cluster Update Settings
|
||||
* API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #putSettings(ClusterUpdateSettingsRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ClusterUpdateSettingsResponse putSettings(ClusterUpdateSettingsRequest clusterUpdateSettingsRequest, Header... headers)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings,
|
||||
|
@ -53,11 +70,26 @@ public final class ClusterClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Asynchronously updates cluster wide specific settings using the Cluster Update Settings API
|
||||
* Asynchronously updates cluster wide specific settings using the Cluster Update Settings API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html"> Cluster Update Settings
|
||||
* API on elastic.co</a>
|
||||
* @param clusterUpdateSettingsRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void putSettingsAsync(ClusterUpdateSettingsRequest clusterUpdateSettingsRequest, RequestOptions options,
|
||||
ActionListener<ClusterUpdateSettingsResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings,
|
||||
options, ClusterUpdateSettingsResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
/**
|
||||
* Asynchronously updates cluster wide specific settings using the Cluster Update Settings API.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html"> Cluster Update Settings
|
||||
* API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #putSettingsAsync(ClusterUpdateSettingsRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void putSettingsAsync(ClusterUpdateSettingsRequest clusterUpdateSettingsRequest,
|
||||
ActionListener<ClusterUpdateSettingsResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(clusterUpdateSettingsRequest, RequestConverters::clusterPutSettings,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ingest.DeletePipelineRequest;
|
||||
import org.elasticsearch.action.ingest.GetPipelineRequest;
|
||||
|
@ -45,70 +44,85 @@ public final class IngestClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a pipeline or update an existing pipeline
|
||||
* <p>
|
||||
* Add a pipeline or update an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public WritePipelineResponse putPipeline(PutPipelineRequest request, Header... headers) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline,
|
||||
WritePipelineResponse::fromXContent, emptySet(), headers);
|
||||
public WritePipelineResponse putPipeline(PutPipelineRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::putPipeline, options,
|
||||
WritePipelineResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously add a pipeline or update an existing pipeline
|
||||
* <p>
|
||||
* Asynchronously add a pipeline or update an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html"> Put Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void putPipelineAsync(PutPipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline,
|
||||
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void putPipelineAsync(PutPipelineRequest request, RequestOptions options, ActionListener<WritePipelineResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::putPipeline, options,
|
||||
WritePipelineResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing pipeline
|
||||
* <p>
|
||||
* Get an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public GetPipelineResponse getPipeline(GetPipelineRequest request, Header... headers) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::getPipeline,
|
||||
GetPipelineResponse::fromXContent, emptySet(), headers);
|
||||
public GetPipelineResponse getPipeline(GetPipelineRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::getPipeline, options,
|
||||
GetPipelineResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get an existing pipeline
|
||||
* <p>
|
||||
* Asynchronously get an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/get-pipeline-api.html"> Get Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void getPipelineAsync(GetPipelineRequest request, ActionListener<GetPipelineResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline,
|
||||
GetPipelineResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void getPipelineAsync(GetPipelineRequest request, RequestOptions options, ActionListener<GetPipelineResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::getPipeline, options,
|
||||
GetPipelineResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing pipeline
|
||||
* <p>
|
||||
* Delete an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
|
||||
* Delete Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public WritePipelineResponse deletePipeline(DeletePipelineRequest request, Header... headers) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline,
|
||||
WritePipelineResponse::fromXContent, emptySet(), headers);
|
||||
public WritePipelineResponse deletePipeline(DeletePipelineRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::deletePipeline, options,
|
||||
WritePipelineResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously delete an existing pipeline
|
||||
* <p>
|
||||
* Asynchronously delete an existing pipeline.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html">
|
||||
* Delete Pipeline API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void deletePipelineAsync(DeletePipelineRequest request, ActionListener<WritePipelineResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline,
|
||||
WritePipelineResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void deletePipelineAsync(DeletePipelineRequest request, RequestOptions options, ActionListener<WritePipelineResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline, options,
|
||||
WritePipelineResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.http.entity.ByteArrayEntity;
|
|||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.action.DocWriteRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
|
||||
|
@ -108,6 +109,17 @@ final class RequestConverters {
|
|||
// Contains only status utility methods
|
||||
}
|
||||
|
||||
static Request cancelTasks(CancelTasksRequest cancelTasksRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME, "/_tasks/_cancel");
|
||||
Params params = new Params(request);
|
||||
params.withTimeout(cancelTasksRequest.getTimeout())
|
||||
.withTaskId(cancelTasksRequest.getTaskId())
|
||||
.withNodes(cancelTasksRequest.getNodes())
|
||||
.withParentTaskId(cancelTasksRequest.getParentTaskId())
|
||||
.withActions(cancelTasksRequest.getActions());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request delete(DeleteRequest deleteRequest) {
|
||||
String endpoint = endpoint(deleteRequest.index(), deleteRequest.type(), deleteRequest.id());
|
||||
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
|
||||
|
@ -710,7 +722,7 @@ final class RequestConverters {
|
|||
return request;
|
||||
}
|
||||
|
||||
static Request getSettings(GetSettingsRequest getSettingsRequest) throws IOException {
|
||||
static Request getSettings(GetSettingsRequest getSettingsRequest) {
|
||||
String[] indices = getSettingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.indices();
|
||||
String[] names = getSettingsRequest.names() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.names();
|
||||
|
||||
|
@ -1070,6 +1082,13 @@ final class RequestConverters {
|
|||
return this;
|
||||
}
|
||||
|
||||
Params withTaskId(TaskId taskId) {
|
||||
if (taskId != null && taskId.isSet()) {
|
||||
return putParam("task_id", taskId.toString());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Params withParentTaskId(TaskId parentTaskId) {
|
||||
if (parentTaskId != null && parentTaskId.isSet()) {
|
||||
return putParam("parent_task_id", parentTaskId.toString());
|
||||
|
|
|
@ -285,16 +285,19 @@ public class RestHighLevelClient implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Executes a bulk request using the Bulk API
|
||||
*
|
||||
* Executes a bulk request using the Bulk API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>
|
||||
* @param bulkRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final BulkResponse bulk(BulkRequest bulkRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(bulkRequest, RequestConverters::bulk, options, BulkResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a bulk request using the Bulk API
|
||||
* Executes a bulk request using the Bulk API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #bulk(BulkRequest, RequestOptions)}
|
||||
|
@ -305,16 +308,18 @@ public class RestHighLevelClient implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a bulk request using the Bulk API
|
||||
*
|
||||
* Asynchronously executes a bulk request using the Bulk API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>
|
||||
* @param bulkRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void bulkAsync(BulkRequest bulkRequest, RequestOptions options, ActionListener<BulkResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(bulkRequest, RequestConverters::bulk, options, BulkResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a bulk request using the Bulk API
|
||||
* Asynchronously executes a bulk request using the Bulk API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html">Bulk API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #bulkAsync(BulkRequest, RequestOptions, ActionListener)}
|
||||
|
@ -326,194 +331,482 @@ public class RestHighLevelClient implements Closeable {
|
|||
|
||||
/**
|
||||
* Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return <code>true</code> if the ping succeeded, false otherwise
|
||||
* @throws IOException in case there is a problem sending the request
|
||||
*/
|
||||
public final boolean ping(RequestOptions options) throws IOException {
|
||||
return performRequest(new MainRequest(), (request) -> RequestConverters.ping(), options, RestHighLevelClient::convertExistsResponse,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise
|
||||
* @deprecated Prefer {@link #ping(RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final boolean ping(Header... headers) throws IOException {
|
||||
return performRequest(new MainRequest(), (request) -> RequestConverters.ping(), RestHighLevelClient::convertExistsResponse,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster info otherwise provided when sending an HTTP request to port 9200
|
||||
* Get the cluster info otherwise provided when sending an HTTP request to '/'
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final MainResponse info(RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(new MainRequest(), (request) -> RequestConverters.info(), options,
|
||||
MainResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster info otherwise provided when sending an HTTP request to port 9200
|
||||
* @deprecated Prefer {@link #info(RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final MainResponse info(Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(new MainRequest(), (request) -> RequestConverters.info(),
|
||||
MainResponse::fromXContent, emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a document by id using the Get API
|
||||
* Retrieves a document by id using the Get API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @param getRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final GetResponse get(GetRequest getRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(getRequest, RequestConverters::get, options, GetResponse::fromXContent, singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a document by id using the Get API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #get(GetRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final GetResponse get(GetRequest getRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(getRequest, RequestConverters::get, GetResponse::fromXContent, singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves a document by id using the Get API
|
||||
* Asynchronously retrieves a document by id using the Get API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @param getRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void getAsync(GetRequest getRequest, RequestOptions options, ActionListener<GetResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(getRequest, RequestConverters::get, options, GetResponse::fromXContent, listener,
|
||||
singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves a document by id using the Get API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #getAsync(GetRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(getRequest, RequestConverters::get, GetResponse::fromXContent, listener,
|
||||
singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves multiple documents by id using the Multi Get API
|
||||
* Retrieves multiple documents by id using the Multi Get API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
|
||||
* @param multiGetRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent,
|
||||
singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves multiple documents by id using the Multi Get API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #multiGet(MultiGetRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(multiGetRequest, RequestConverters::multiGet, MultiGetResponse::fromXContent,
|
||||
singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves multiple documents by id using the Multi Get API
|
||||
* Asynchronously retrieves multiple documents by id using the Multi Get API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
|
||||
* @param multiGetRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void multiGetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent, listener,
|
||||
singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves multiple documents by id using the Multi Get API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #multiGetAsync(MultiGetRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void multiGetAsync(MultiGetRequest multiGetRequest, ActionListener<MultiGetResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(multiGetRequest, RequestConverters::multiGet, MultiGetResponse::fromXContent, listener,
|
||||
singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the existence of a document. Returns true if it exists, false otherwise
|
||||
* Checks for the existence of a document. Returns true if it exists, false otherwise.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @param getRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return <code>true</code> if the document exists, <code>false</code> otherwise
|
||||
* @throws IOException in case there is a problem sending the request
|
||||
*/
|
||||
public final boolean exists(GetRequest getRequest, RequestOptions options) throws IOException {
|
||||
return performRequest(getRequest, RequestConverters::exists, options, RestHighLevelClient::convertExistsResponse, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the existence of a document. Returns true if it exists, false otherwise.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #exists(GetRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final boolean exists(GetRequest getRequest, Header... headers) throws IOException {
|
||||
return performRequest(getRequest, RequestConverters::exists, RestHighLevelClient::convertExistsResponse, emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously checks for the existence of a document. Returns true if it exists, false otherwise
|
||||
* Asynchronously checks for the existence of a document. Returns true if it exists, false otherwise.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @param getRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void existsAsync(GetRequest getRequest, RequestOptions options, ActionListener<Boolean> listener) {
|
||||
performRequestAsync(getRequest, RequestConverters::exists, options, RestHighLevelClient::convertExistsResponse, listener,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously checks for the existence of a document. Returns true if it exists, false otherwise.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #existsAsync(GetRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void existsAsync(GetRequest getRequest, ActionListener<Boolean> listener, Header... headers) {
|
||||
performRequestAsync(getRequest, RequestConverters::exists, RestHighLevelClient::convertExistsResponse, listener,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index a document using the Index API
|
||||
* Index a document using the Index API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html">Index API on elastic.co</a>
|
||||
* @param indexRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final IndexResponse index(IndexRequest indexRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(indexRequest, RequestConverters::index, options, IndexResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Index a document using the Index API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html">Index API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #index(IndexRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final IndexResponse index(IndexRequest indexRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(indexRequest, RequestConverters::index, IndexResponse::fromXContent, emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously index a document using the Index API
|
||||
* Asynchronously index a document using the Index API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html">Index API on elastic.co</a>
|
||||
* @param indexRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void indexAsync(IndexRequest indexRequest, RequestOptions options, ActionListener<IndexResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(indexRequest, RequestConverters::index, options, IndexResponse::fromXContent, listener,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously index a document using the Index API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html">Index API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #indexAsync(IndexRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void indexAsync(IndexRequest indexRequest, ActionListener<IndexResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(indexRequest, RequestConverters::index, IndexResponse::fromXContent, listener,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a document using the Update API
|
||||
* Updates a document using the Update API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html">Update API on elastic.co</a>
|
||||
* @param updateRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final UpdateResponse update(UpdateRequest updateRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(updateRequest, RequestConverters::update, options, UpdateResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a document using the Update API.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html">Update API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #update(UpdateRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final UpdateResponse update(UpdateRequest updateRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(updateRequest, RequestConverters::update, UpdateResponse::fromXContent, emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously updates a document using the Update API
|
||||
* Asynchronously updates a document using the Update API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html">Update API on elastic.co</a>
|
||||
* @param updateRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void updateAsync(UpdateRequest updateRequest, RequestOptions options, ActionListener<UpdateResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(updateRequest, RequestConverters::update, options, UpdateResponse::fromXContent, listener,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously updates a document using the Update API.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html">Update API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #updateAsync(UpdateRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void updateAsync(UpdateRequest updateRequest, ActionListener<UpdateResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(updateRequest, RequestConverters::update, UpdateResponse::fromXContent, listener,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a document by id using the Delete API
|
||||
* Deletes a document by id using the Delete API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
|
||||
* @param deleteRequest the reuqest
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final DeleteResponse delete(DeleteRequest deleteRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(deleteRequest, RequestConverters::delete, options, DeleteResponse::fromXContent,
|
||||
singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a document by id using the Delete API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #delete(DeleteRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final DeleteResponse delete(DeleteRequest deleteRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(deleteRequest, RequestConverters::delete, DeleteResponse::fromXContent,
|
||||
singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously deletes a document by id using the Delete API
|
||||
*
|
||||
* Asynchronously deletes a document by id using the Delete API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
|
||||
* @param deleteRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void deleteAsync(DeleteRequest deleteRequest, ActionListener<DeleteResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(deleteRequest, RequestConverters::delete, DeleteResponse::fromXContent, listener,
|
||||
Collections.singleton(404), headers);
|
||||
public final void deleteAsync(DeleteRequest deleteRequest, RequestOptions options, ActionListener<DeleteResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(deleteRequest, RequestConverters::delete, options, DeleteResponse::fromXContent, listener,
|
||||
Collections.singleton(404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search using the Search API
|
||||
* Asynchronously deletes a document by id using the Delete API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html">Delete API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #deleteAsync(DeleteRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void deleteAsync(DeleteRequest deleteRequest, ActionListener<DeleteResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(deleteRequest, RequestConverters::delete, DeleteResponse::fromXContent, listener,
|
||||
Collections.singleton(404), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search request using the Search API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
|
||||
* @param searchRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final SearchResponse search(SearchRequest searchRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(searchRequest, RequestConverters::search, options, SearchResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search using the Search API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #search(SearchRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final SearchResponse search(SearchRequest searchRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(searchRequest, RequestConverters::search, SearchResponse::fromXContent, emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a search using the Search API
|
||||
* Asynchronously executes a search using the Search API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
|
||||
* @param searchRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void searchAsync(SearchRequest searchRequest, RequestOptions options, ActionListener<SearchResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::search, options, SearchResponse::fromXContent, listener,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a search using the Search API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #searchAsync(SearchRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void searchAsync(SearchRequest searchRequest, ActionListener<SearchResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::search, SearchResponse::fromXContent, listener,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a multi search using the msearch API
|
||||
* Executes a multi search using the msearch API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
|
||||
* elastic.co</a>
|
||||
* @param multiSearchRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(multiSearchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a multi search using the msearch API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
|
||||
* elastic.co</a>
|
||||
* @deprecated Prefer {@link #multiSearch(MultiSearchRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(multiSearchRequest, RequestConverters::multiSearch, MultiSearchResponse::fromXContext,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a multi search using the msearch API
|
||||
* Asynchronously executes a multi search using the msearch API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
|
||||
* elastic.co</a>
|
||||
* @param searchRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void multiSearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
|
||||
ActionListener<MultiSearchResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
|
||||
listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a multi search using the msearch API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
|
||||
* elastic.co</a>
|
||||
* @deprecated Prefer {@link #multiSearchAsync(MultiSearchRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void multiSearchAsync(MultiSearchRequest searchRequest, ActionListener<MultiSearchResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::multiSearch, MultiSearchResponse::fromXContext, listener,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search using the Search Scroll API
|
||||
* Executes a search using the Search Scroll API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
|
||||
* API on elastic.co</a>
|
||||
* @param searchScrollRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a search using the Search Scroll API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
|
||||
* API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #searchScroll(SearchScrollRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, SearchResponse::fromXContent,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a search using the Search Scroll API
|
||||
* Asynchronously executes a search using the Search Scroll API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
|
||||
* API on elastic.co</a>
|
||||
* @param searchScrollRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
|
||||
ActionListener<SearchResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
|
||||
listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a search using the Search Scroll API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
|
||||
* API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #searchScrollAsync(SearchScrollRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void searchScrollAsync(SearchScrollRequest searchScrollRequest,
|
||||
ActionListener<SearchResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, SearchResponse::fromXContent,
|
||||
|
@ -521,22 +814,54 @@ public class RestHighLevelClient implements Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Clears one or more scroll ids using the Clear Scroll API
|
||||
* Clears one or more scroll ids using the Clear Scroll API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
|
||||
* Clear Scroll API on elastic.co</a>
|
||||
* @param clearScrollRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(clearScrollRequest, RequestConverters::clearScroll, options, ClearScrollResponse::fromXContent,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears one or more scroll ids using the Clear Scroll API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
|
||||
* Clear Scroll API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #clearScroll(ClearScrollRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(clearScrollRequest, RequestConverters::clearScroll, ClearScrollResponse::fromXContent,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously clears one or more scroll ids using the Clear Scroll API
|
||||
* Asynchronously clears one or more scroll ids using the Clear Scroll API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
|
||||
* Clear Scroll API on elastic.co</a>
|
||||
* @param clearScrollRequest the reuqest
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void clearScrollAsync(ClearScrollRequest clearScrollRequest, RequestOptions options,
|
||||
ActionListener<ClearScrollResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(clearScrollRequest, RequestConverters::clearScroll, options, ClearScrollResponse::fromXContent,
|
||||
listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously clears one or more scroll ids using the Clear Scroll API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api">
|
||||
* Clear Scroll API on elastic.co</a>
|
||||
* @deprecated Prefer {@link #clearScrollAsync(ClearScrollRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void clearScrollAsync(ClearScrollRequest clearScrollRequest,
|
||||
ActionListener<ClearScrollResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(clearScrollRequest, RequestConverters::clearScroll, ClearScrollResponse::fromXContent,
|
||||
|
@ -545,47 +870,79 @@ public class RestHighLevelClient implements Closeable {
|
|||
|
||||
/**
|
||||
* Executes a request using the Search Template API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html">Search Template API
|
||||
* on elastic.co</a>.
|
||||
* @param searchTemplateRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final SearchTemplateResponse searchTemplate(SearchTemplateRequest searchTemplateRequest,
|
||||
Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(searchTemplateRequest, RequestConverters::searchTemplate,
|
||||
SearchTemplateResponse::fromXContent, emptySet(), headers);
|
||||
RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(searchTemplateRequest, RequestConverters::searchTemplate, options,
|
||||
SearchTemplateResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a request using the Search Template API
|
||||
* Asynchronously executes a request using the Search Template API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html">Search Template API
|
||||
* on elastic.co</a>.
|
||||
*/
|
||||
public final void searchTemplateAsync(SearchTemplateRequest searchTemplateRequest,
|
||||
ActionListener<SearchTemplateResponse> listener,
|
||||
Header... headers) {
|
||||
performRequestAsyncAndParseEntity(searchTemplateRequest, RequestConverters::searchTemplate,
|
||||
SearchTemplateResponse::fromXContent, listener, emptySet(), headers);
|
||||
public final void searchTemplateAsync(SearchTemplateRequest searchTemplateRequest, RequestOptions options,
|
||||
ActionListener<SearchTemplateResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(searchTemplateRequest, RequestConverters::searchTemplate, options,
|
||||
SearchTemplateResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a request using the Ranking Evaluation API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html">Ranking Evaluation API
|
||||
* on elastic.co</a>
|
||||
* @param rankEvalRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final RankEvalResponse rankEval(RankEvalRequest rankEvalRequest, RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(rankEvalRequest, RequestConverters::rankEval, options, RankEvalResponse::fromXContent,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a request using the Ranking Evaluation API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html">Ranking Evaluation API
|
||||
* on elastic.co</a>
|
||||
* @deprecated Prefer {@link #rankEval(RankEvalRequest, RequestOptions)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final RankEvalResponse rankEval(RankEvalRequest rankEvalRequest, Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(rankEvalRequest, RequestConverters::rankEval, RankEvalResponse::fromXContent,
|
||||
emptySet(), headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a request using the Ranking Evaluation API.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html">Ranking Evaluation API
|
||||
* on elastic.co</a>
|
||||
* @param rankEvalRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void rankEvalAsync(RankEvalRequest rankEvalRequest, RequestOptions options, ActionListener<RankEvalResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(rankEvalRequest, RequestConverters::rankEval, options, RankEvalResponse::fromXContent, listener,
|
||||
emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a request using the Ranking Evaluation API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html">Ranking Evaluation API
|
||||
* on elastic.co</a>
|
||||
* @deprecated Prefer {@link #rankEvalAsync(RankEvalRequest, RequestOptions, ActionListener)}
|
||||
*/
|
||||
@Deprecated
|
||||
public final void rankEvalAsync(RankEvalRequest rankEvalRequest, ActionListener<RankEvalResponse> listener, Header... headers) {
|
||||
performRequestAsyncAndParseEntity(rankEvalRequest, RequestConverters::rankEval, RankEvalResponse::fromXContent, listener,
|
||||
emptySet(), headers);
|
||||
|
@ -593,27 +950,31 @@ public class RestHighLevelClient implements Closeable {
|
|||
|
||||
/**
|
||||
* Executes a request using the Field Capabilities API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html">Field Capabilities API
|
||||
* on elastic.co</a>.
|
||||
* @param fieldCapabilitiesRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public final FieldCapabilitiesResponse fieldCaps(FieldCapabilitiesRequest fieldCapabilitiesRequest,
|
||||
Header... headers) throws IOException {
|
||||
return performRequestAndParseEntity(fieldCapabilitiesRequest, RequestConverters::fieldCaps,
|
||||
FieldCapabilitiesResponse::fromXContent, emptySet(), headers);
|
||||
RequestOptions options) throws IOException {
|
||||
return performRequestAndParseEntity(fieldCapabilitiesRequest, RequestConverters::fieldCaps, options,
|
||||
FieldCapabilitiesResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously executes a request using the Field Capabilities API.
|
||||
*
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html">Field Capabilities API
|
||||
* on elastic.co</a>.
|
||||
* @param fieldCapabilitiesRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesRequest,
|
||||
ActionListener<FieldCapabilitiesResponse> listener,
|
||||
Header... headers) {
|
||||
performRequestAsyncAndParseEntity(fieldCapabilitiesRequest, RequestConverters::fieldCaps,
|
||||
FieldCapabilitiesResponse::fromXContent, listener, emptySet(), headers);
|
||||
public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesRequest, RequestOptions options,
|
||||
ActionListener<FieldCapabilitiesResponse> listener) {
|
||||
performRequestAsyncAndParseEntity(fieldCapabilitiesRequest, RequestConverters::fieldCaps, options,
|
||||
FieldCapabilitiesResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse;
|
||||
|
@ -49,97 +48,117 @@ public final class SnapshotClient {
|
|||
/**
|
||||
* Gets a list of snapshot repositories. If the list of repositories is empty or it contains a single element "_all", all
|
||||
* registered repositories are returned.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param getRepositoriesRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public GetRepositoriesResponse getRepositories(GetRepositoriesRequest getRepositoriesRequest, Header... headers)
|
||||
public GetRepositoriesResponse getRepositories(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories,
|
||||
GetRepositoriesResponse::fromXContent, emptySet(), headers);
|
||||
return restHighLevelClient.performRequestAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
|
||||
GetRepositoriesResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously gets a list of snapshot repositories. If the list of repositories is empty or it contains a single element "_all", all
|
||||
* registered repositories are returned.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param getRepositoriesRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void getRepositoriesAsync(GetRepositoriesRequest getRepositoriesRequest,
|
||||
ActionListener<GetRepositoriesResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories,
|
||||
GetRepositoriesResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void getRepositoriesAsync(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options,
|
||||
ActionListener<GetRepositoriesResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
|
||||
GetRepositoriesResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param putRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public PutRepositoryResponse createRepository(PutRepositoryRequest putRepositoryRequest, Header... headers) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(putRepositoryRequest, RequestConverters::createRepository,
|
||||
PutRepositoryResponse::fromXContent, emptySet(), headers);
|
||||
public PutRepositoryResponse createRepository(PutRepositoryRequest putRepositoryRequest, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(putRepositoryRequest, RequestConverters::createRepository, options,
|
||||
PutRepositoryResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously creates a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param putRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void createRepositoryAsync(PutRepositoryRequest putRepositoryRequest,
|
||||
ActionListener<PutRepositoryResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(putRepositoryRequest, RequestConverters::createRepository,
|
||||
PutRepositoryResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void createRepositoryAsync(PutRepositoryRequest putRepositoryRequest, RequestOptions options,
|
||||
ActionListener<PutRepositoryResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(putRepositoryRequest, RequestConverters::createRepository, options,
|
||||
PutRepositoryResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param deleteRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public DeleteRepositoryResponse deleteRepository(DeleteRepositoryRequest deleteRepositoryRequest, Header... headers)
|
||||
public DeleteRepositoryResponse deleteRepository(DeleteRepositoryRequest deleteRepositoryRequest, RequestOptions options)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(deleteRepositoryRequest, RequestConverters::deleteRepository,
|
||||
DeleteRepositoryResponse::fromXContent, emptySet(), headers);
|
||||
return restHighLevelClient.performRequestAndParseEntity(deleteRepositoryRequest, RequestConverters::deleteRepository, options,
|
||||
DeleteRepositoryResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously deletes a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param deleteRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void deleteRepositoryAsync(DeleteRepositoryRequest deleteRepositoryRequest,
|
||||
ActionListener<DeleteRepositoryResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(deleteRepositoryRequest, RequestConverters::deleteRepository,
|
||||
DeleteRepositoryResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void deleteRepositoryAsync(DeleteRepositoryRequest deleteRepositoryRequest, RequestOptions options,
|
||||
ActionListener<DeleteRepositoryResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(deleteRepositoryRequest, RequestConverters::deleteRepository, options,
|
||||
DeleteRepositoryResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param verifyRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public VerifyRepositoryResponse verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest, Header... headers)
|
||||
public VerifyRepositoryResponse verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest, RequestOptions options)
|
||||
throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository,
|
||||
VerifyRepositoryResponse::fromXContent, emptySet(), headers);
|
||||
return restHighLevelClient.performRequestAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository, options,
|
||||
VerifyRepositoryResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously verifies a snapshot repository.
|
||||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
|
||||
* API on elastic.co</a>
|
||||
* @param verifyRepositoryRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void verifyRepositoryAsync(VerifyRepositoryRequest verifyRepositoryRequest,
|
||||
ActionListener<VerifyRepositoryResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository,
|
||||
VerifyRepositoryResponse::fromXContent, listener, emptySet(), headers);
|
||||
public void verifyRepositoryAsync(VerifyRepositoryRequest verifyRepositoryRequest, RequestOptions options,
|
||||
ActionListener<VerifyRepositoryResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository, options,
|
||||
VerifyRepositoryResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
|
||||
|
@ -33,7 +34,7 @@ import static java.util.Collections.emptySet;
|
|||
* <p>
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html">Task Management API on elastic.co</a>
|
||||
*/
|
||||
public class TasksClient {
|
||||
public final class TasksClient {
|
||||
private final RestHighLevelClient restHighLevelClient;
|
||||
|
||||
TasksClient(RestHighLevelClient restHighLevelClient) {
|
||||
|
@ -41,24 +42,70 @@ public class TasksClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get current tasks using the Task Management API
|
||||
* <p>
|
||||
* Get current tasks using the Task Management API.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*/
|
||||
public ListTasksResponse list(ListTasksRequest request, Header... headers) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::listTasks, ListTasksResponse::fromXContent,
|
||||
emptySet(), headers);
|
||||
public ListTasksResponse list(ListTasksRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::listTasks, options,
|
||||
ListTasksResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get current tasks using the Task Management API
|
||||
* <p>
|
||||
* Asynchronously get current tasks using the Task Management API.
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
|
||||
* @param request the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void listAsync(ListTasksRequest request, ActionListener<ListTasksResponse> listener, Header... headers) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::listTasks, ListTasksResponse::fromXContent,
|
||||
listener, emptySet(), headers);
|
||||
public void listAsync(ListTasksRequest request, RequestOptions options, ActionListener<ListTasksResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::listTasks, options,
|
||||
ListTasksResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel one or more cluster tasks using the Task Management API.
|
||||
*
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
|
||||
* @param cancelTasksRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return the response
|
||||
* @throws IOException in case there is a problem sending the request or parsing back the response
|
||||
*
|
||||
*/
|
||||
public CancelTasksResponse cancel(CancelTasksRequest cancelTasksRequest, RequestOptions options ) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(
|
||||
cancelTasksRequest,
|
||||
RequestConverters::cancelTasks,
|
||||
options,
|
||||
parser -> CancelTasksResponse.fromXContent(parser),
|
||||
emptySet()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously cancel one or more cluster tasks using the Task Management API.
|
||||
*
|
||||
* See
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html"> Task Management API on elastic.co</a>
|
||||
* @param cancelTasksRequest the request
|
||||
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @param listener the listener to be notified upon request completion
|
||||
*/
|
||||
public void cancelAsync(CancelTasksRequest cancelTasksRequest, RequestOptions options, ActionListener<CancelTasksResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
cancelTasksRequest,
|
||||
RequestConverters::cancelTasks,
|
||||
options,
|
||||
parser -> CancelTasksResponse.fromXContent(parser),
|
||||
listener,
|
||||
emptySet()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||
import org.elasticsearch.action.bulk.BulkProcessor;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
|
@ -39,7 +37,6 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -81,7 +78,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
|
|||
assertThat(listener.afterCounts.get(), equalTo(1));
|
||||
assertThat(listener.bulkFailures.size(), equalTo(0));
|
||||
assertResponseItems(listener.bulkItems, numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest), numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +104,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
|
|||
assertThat(listener.afterCounts.get(), equalTo(1));
|
||||
assertThat(listener.bulkFailures.size(), equalTo(0));
|
||||
assertResponseItems(listener.bulkItems, numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest), numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +156,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
|
|||
assertThat(ids.add(bulkItemResponse.getId()), equalTo(true));
|
||||
}
|
||||
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest), numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
|
||||
}
|
||||
|
||||
public void testBulkProcessorWaitOnClose() throws Exception {
|
||||
|
@ -190,7 +187,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
assertThat(listener.bulkFailures.size(), equalTo(0));
|
||||
assertResponseItems(listener.bulkItems, numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest), numDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), numDocs);
|
||||
}
|
||||
|
||||
public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception {
|
||||
|
@ -267,7 +264,7 @@ public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest), testDocs);
|
||||
assertMultiGetResponse(highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT), testDocs);
|
||||
}
|
||||
|
||||
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception {
|
||||
|
|
|
@ -127,8 +127,8 @@ public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
highLevelClient().indices().refresh(new RefreshRequest());
|
||||
int multiGetResponsesCount = highLevelClient().multiGet(multiGetRequest).getResponses().length;
|
||||
highLevelClient().indices().refresh(new RefreshRequest(), RequestOptions.DEFAULT);
|
||||
int multiGetResponsesCount = highLevelClient().multiGet(multiGetRequest, RequestOptions.DEFAULT).getResponses().length;
|
||||
|
||||
if (rejectedExecutionExpected) {
|
||||
assertThat(multiGetResponsesCount, lessThanOrEqualTo(numberOfAsyncOps));
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
|
|||
setRequest.persistentSettings(map);
|
||||
|
||||
ClusterUpdateSettingsResponse setResponse = execute(setRequest, highLevelClient().cluster()::putSettings,
|
||||
highLevelClient().cluster()::putSettingsAsync, highLevelClient().cluster()::putSettings,
|
||||
highLevelClient().cluster()::putSettingsAsync);
|
||||
|
||||
assertAcked(setResponse);
|
||||
|
@ -79,6 +80,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
|
|||
resetRequest.persistentSettings("{\"" + persistentSettingKey + "\": null }", XContentType.JSON);
|
||||
|
||||
ClusterUpdateSettingsResponse resetResponse = execute(resetRequest, highLevelClient().cluster()::putSettings,
|
||||
highLevelClient().cluster()::putSettingsAsync, highLevelClient().cluster()::putSettings,
|
||||
highLevelClient().cluster()::putSettingsAsync);
|
||||
|
||||
assertThat(resetResponse.getTransientSettings().get(transientSettingKey), equalTo(null));
|
||||
|
@ -100,6 +102,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
|
|||
clusterUpdateSettingsRequest.transientSettings(Settings.builder().put(setting, value).build());
|
||||
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(clusterUpdateSettingsRequest,
|
||||
highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync,
|
||||
highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync));
|
||||
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
|
||||
assertThat(exception.getMessage(), equalTo(
|
||||
|
|
|
@ -68,12 +68,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// Testing deletion
|
||||
String docId = "id";
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")));
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
|
||||
if (randomBoolean()) {
|
||||
deleteRequest.version(1L);
|
||||
}
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
assertEquals("index", deleteResponse.getIndex());
|
||||
assertEquals("type", deleteResponse.getType());
|
||||
assertEquals(docId, deleteResponse.getId());
|
||||
|
@ -83,7 +85,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
// Testing non existing document
|
||||
String docId = "does_not_exist";
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
assertEquals("index", deleteResponse.getIndex());
|
||||
assertEquals("type", deleteResponse.getType());
|
||||
assertEquals(docId, deleteResponse.getId());
|
||||
|
@ -92,10 +95,12 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// Testing version conflict
|
||||
String docId = "version_conflict";
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")));
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).version(2);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync));
|
||||
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync));
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[type][" + docId + "]: " +
|
||||
"version conflict, current version [1] is different than the one provided [2]]", exception.getMessage());
|
||||
|
@ -104,10 +109,12 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// Testing version type
|
||||
String docId = "version_type";
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
|
||||
.versionType(VersionType.EXTERNAL).version(12));
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
|
||||
.versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT);
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(13);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
assertEquals("index", deleteResponse.getIndex());
|
||||
assertEquals("type", deleteResponse.getType());
|
||||
assertEquals(docId, deleteResponse.getId());
|
||||
|
@ -116,11 +123,13 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// Testing version type with a wrong version
|
||||
String docId = "wrong_version";
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
|
||||
.versionType(VersionType.EXTERNAL).version(12));
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar"))
|
||||
.versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT);
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> {
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).versionType(VersionType.EXTERNAL).version(10);
|
||||
execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
});
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[type][" +
|
||||
|
@ -130,9 +139,11 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// Testing routing
|
||||
String docId = "routing";
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")).routing("foo"));
|
||||
highLevelClient().index(new IndexRequest("index", "type", docId).source(Collections.singletonMap("foo", "bar")).routing("foo"),
|
||||
RequestOptions.DEFAULT);
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "type", docId).routing("foo");
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync,
|
||||
highLevelClient()::delete, highLevelClient()::deleteAsync);
|
||||
assertEquals("index", deleteResponse.getIndex());
|
||||
assertEquals("type", deleteResponse.getType());
|
||||
assertEquals(docId, deleteResponse.getId());
|
||||
|
@ -143,23 +154,27 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
public void testExists() throws IOException {
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id");
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync,
|
||||
highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
}
|
||||
IndexRequest index = new IndexRequest("index", "type", "id");
|
||||
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
|
||||
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
|
||||
highLevelClient().index(index);
|
||||
highLevelClient().index(index, RequestOptions.DEFAULT);
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id");
|
||||
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync,
|
||||
highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "does_not_exist");
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync,
|
||||
highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "does_not_exist").version(1);
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync,
|
||||
highLevelClient()::exists, highLevelClient()::existsAsync));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +182,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id");
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
|
||||
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index]", exception.getMessage());
|
||||
assertEquals("index", exception.getMetadata("es.index").get(0));
|
||||
|
@ -176,11 +192,12 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
String document = "{\"field1\":\"value1\",\"field2\":\"value2\"}";
|
||||
index.source(document, XContentType.JSON);
|
||||
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
|
||||
highLevelClient().index(index);
|
||||
highLevelClient().index(index, RequestOptions.DEFAULT);
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id").version(2);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
|
||||
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync));
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, " + "reason=[type][id]: " +
|
||||
"version conflict, current version [1] is different than the one provided [2]]", exception.getMessage());
|
||||
|
@ -191,7 +208,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
if (randomBoolean()) {
|
||||
getRequest.version(1L);
|
||||
}
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync);
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
assertEquals("id", getResponse.getId());
|
||||
|
@ -202,7 +220,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "does_not_exist");
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync);
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
assertEquals("does_not_exist", getResponse.getId());
|
||||
|
@ -214,7 +233,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id");
|
||||
getRequest.fetchSourceContext(new FetchSourceContext(false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY));
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync);
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
assertEquals("id", getResponse.getId());
|
||||
|
@ -230,7 +250,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
} else {
|
||||
getRequest.fetchSourceContext(new FetchSourceContext(true, Strings.EMPTY_ARRAY, new String[]{"field2"}));
|
||||
}
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
|
||||
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync,
|
||||
highLevelClient()::get, highLevelClient()::getAsync);
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
assertEquals("id", getResponse.getId());
|
||||
|
@ -248,7 +269,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
multiGetRequest.add("index", "type", "id1");
|
||||
multiGetRequest.add("index", "type", "id2");
|
||||
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
|
||||
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync,
|
||||
highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
|
||||
assertEquals(2, response.getResponses().length);
|
||||
|
||||
assertTrue(response.getResponses()[0].isFailed());
|
||||
|
@ -275,12 +297,13 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
index = new IndexRequest("index", "type", "id2");
|
||||
index.source("{\"field\":\"value2\"}", XContentType.JSON);
|
||||
bulk.add(index);
|
||||
highLevelClient().bulk(bulk);
|
||||
highLevelClient().bulk(bulk, RequestOptions.DEFAULT);
|
||||
{
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
multiGetRequest.add("index", "type", "id1");
|
||||
multiGetRequest.add("index", "type", "id2");
|
||||
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
|
||||
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::multiGet, highLevelClient()::multiGetAsync,
|
||||
highLevelClient()::multiGet, highLevelClient()::multiGetAsync);
|
||||
assertEquals(2, response.getResponses().length);
|
||||
|
||||
assertFalse(response.getResponses()[0].isFailed());
|
||||
|
@ -305,7 +328,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest indexRequest = new IndexRequest("index", "type");
|
||||
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("test", "test").endObject());
|
||||
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
|
@ -326,7 +350,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
|
||||
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("version", 1).endObject());
|
||||
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
|
@ -336,7 +361,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
indexRequest = new IndexRequest("index", "type", "id");
|
||||
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("version", 2).endObject());
|
||||
|
||||
indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
assertEquals(RestStatus.OK, indexResponse.status());
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
|
@ -348,7 +374,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
wrongRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject());
|
||||
wrongRequest.version(5L);
|
||||
|
||||
execute(wrongRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
execute(wrongRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
});
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[type][id]: " +
|
||||
|
@ -361,7 +388,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject());
|
||||
indexRequest.setPipeline("missing");
|
||||
|
||||
execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
});
|
||||
|
||||
assertEquals(RestStatus.BAD_REQUEST, exception.status());
|
||||
|
@ -374,7 +402,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
indexRequest.version(12L);
|
||||
indexRequest.versionType(VersionType.EXTERNAL);
|
||||
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
|
@ -386,14 +415,16 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
indexRequest.source(XContentBuilder.builder(xContentType.xContent()).startObject().field("field", "test").endObject());
|
||||
indexRequest.opType(DocWriteRequest.OpType.CREATE);
|
||||
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
IndexResponse indexResponse = execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
assertEquals("with_create_op_type", indexResponse.getId());
|
||||
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> {
|
||||
execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
execute(indexRequest, highLevelClient()::index, highLevelClient()::indexAsync,
|
||||
highLevelClient()::index, highLevelClient()::indexAsync);
|
||||
});
|
||||
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
|
@ -408,7 +439,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values()));
|
||||
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () ->
|
||||
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync));
|
||||
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=document_missing_exception, reason=[type][does_not_exist]: document missing]",
|
||||
exception.getMessage());
|
||||
|
@ -416,7 +448,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
|
||||
indexRequest.source(singletonMap("field", "value"));
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
|
||||
UpdateRequest updateRequest = new UpdateRequest("index", "type", "id");
|
||||
|
@ -431,7 +463,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequestConflict.version(indexResponse.getVersion());
|
||||
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () ->
|
||||
execute(updateRequestConflict, highLevelClient()::update, highLevelClient()::updateAsync));
|
||||
execute(updateRequestConflict, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync));
|
||||
assertEquals(RestStatus.CONFLICT, exception.status());
|
||||
assertEquals("Elasticsearch exception [type=version_conflict_engine_exception, reason=[type][id]: version conflict, " +
|
||||
"current version [2] is different than the one provided [1]]", exception.getMessage());
|
||||
|
@ -439,7 +472,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
IndexRequest indexRequest = new IndexRequest("index", "type", "with_script");
|
||||
indexRequest.source(singletonMap("counter", 12));
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
|
||||
UpdateRequest updateRequest = new UpdateRequest("index", "type", "with_script");
|
||||
|
@ -447,7 +480,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.script(script);
|
||||
updateRequest.fetchSource(true);
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.OK, updateResponse.status());
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertEquals(2L, updateResponse.getVersion());
|
||||
|
@ -459,7 +493,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
indexRequest.source("field_1", "one", "field_3", "three");
|
||||
indexRequest.version(12L);
|
||||
indexRequest.versionType(VersionType.EXTERNAL);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals(12L, indexResponse.getVersion());
|
||||
|
||||
|
@ -467,7 +501,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.doc(singletonMap("field_2", "two"), randomFrom(XContentType.values()));
|
||||
updateRequest.fetchSource("field_*", "field_3");
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.OK, updateResponse.status());
|
||||
assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult());
|
||||
assertEquals(13L, updateResponse.getVersion());
|
||||
|
@ -481,14 +516,15 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
IndexRequest indexRequest = new IndexRequest("index", "type", "noop");
|
||||
indexRequest.source("field", "value");
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(RestStatus.CREATED, indexResponse.status());
|
||||
assertEquals(1L, indexResponse.getVersion());
|
||||
|
||||
UpdateRequest updateRequest = new UpdateRequest("index", "type", "noop");
|
||||
updateRequest.doc(singletonMap("field", "value"), randomFrom(XContentType.values()));
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.OK, updateResponse.status());
|
||||
assertEquals(DocWriteResponse.Result.NOOP, updateResponse.getResult());
|
||||
assertEquals(1L, updateResponse.getVersion());
|
||||
|
@ -506,7 +542,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.doc(singletonMap("doc_status", "updated"));
|
||||
updateRequest.fetchSource(true);
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.CREATED, updateResponse.status());
|
||||
assertEquals("index", updateResponse.getIndex());
|
||||
assertEquals("type", updateResponse.getType());
|
||||
|
@ -521,7 +558,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.fetchSource(true);
|
||||
updateRequest.docAsUpsert(true);
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.CREATED, updateResponse.status());
|
||||
assertEquals("index", updateResponse.getIndex());
|
||||
assertEquals("type", updateResponse.getType());
|
||||
|
@ -537,7 +575,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
updateRequest.scriptedUpsert(true);
|
||||
updateRequest.upsert(singletonMap("level", "A"));
|
||||
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
UpdateResponse updateResponse = execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
assertEquals(RestStatus.CREATED, updateResponse.status());
|
||||
assertEquals("index", updateResponse.getIndex());
|
||||
assertEquals("type", updateResponse.getType());
|
||||
|
@ -552,7 +591,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateRequest updateRequest = new UpdateRequest("index", "type", "id");
|
||||
updateRequest.doc(new IndexRequest().source(Collections.singletonMap("field", "doc"), XContentType.JSON));
|
||||
updateRequest.upsert(new IndexRequest().source(Collections.singletonMap("field", "upsert"), XContentType.YAML));
|
||||
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
execute(updateRequest, highLevelClient()::update, highLevelClient()::updateAsync,
|
||||
highLevelClient()::update, highLevelClient()::updateAsync);
|
||||
});
|
||||
assertEquals("Update request cannot have different content types for doc [JSON] and upsert [YAML] documents",
|
||||
exception.getMessage());
|
||||
|
@ -575,7 +615,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
if (opType == DocWriteRequest.OpType.DELETE) {
|
||||
if (erroneous == false) {
|
||||
assertEquals(RestStatus.CREATED,
|
||||
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "test", id).source("field", -1), RequestOptions.DEFAULT).status());
|
||||
}
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "test", id);
|
||||
bulkRequest.add(deleteRequest);
|
||||
|
@ -593,7 +634,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
} else if (opType == DocWriteRequest.OpType.CREATE) {
|
||||
IndexRequest createRequest = new IndexRequest("index", "test", id).source(source, xContentType).create(true);
|
||||
if (erroneous) {
|
||||
assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest).status());
|
||||
assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest, RequestOptions.DEFAULT).status());
|
||||
}
|
||||
bulkRequest.add(createRequest);
|
||||
|
||||
|
@ -602,14 +643,16 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
.doc(new IndexRequest().source(source, xContentType));
|
||||
if (erroneous == false) {
|
||||
assertEquals(RestStatus.CREATED,
|
||||
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "test", id).source("field", -1), RequestOptions.DEFAULT).status());
|
||||
}
|
||||
bulkRequest.add(updateRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BulkResponse bulkResponse = execute(bulkRequest, highLevelClient()::bulk, highLevelClient()::bulkAsync);
|
||||
BulkResponse bulkResponse = execute(bulkRequest, highLevelClient()::bulk, highLevelClient()::bulkAsync,
|
||||
highLevelClient()::bulk, highLevelClient()::bulkAsync);
|
||||
assertEquals(RestStatus.OK, bulkResponse.status());
|
||||
assertTrue(bulkResponse.getTook().getMillis() > 0);
|
||||
assertEquals(nbItems, bulkResponse.getItems().length);
|
||||
|
@ -662,7 +705,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
if (opType == DocWriteRequest.OpType.DELETE) {
|
||||
if (erroneous == false) {
|
||||
assertEquals(RestStatus.CREATED,
|
||||
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "test", id).source("field", -1), RequestOptions.DEFAULT).status());
|
||||
}
|
||||
DeleteRequest deleteRequest = new DeleteRequest("index", "test", id);
|
||||
processor.add(deleteRequest);
|
||||
|
@ -678,7 +722,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
} else if (opType == DocWriteRequest.OpType.CREATE) {
|
||||
IndexRequest createRequest = new IndexRequest("index", "test", id).source(xContentType, "id", i).create(true);
|
||||
if (erroneous) {
|
||||
assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest).status());
|
||||
assertEquals(RestStatus.CREATED, highLevelClient().index(createRequest, RequestOptions.DEFAULT).status());
|
||||
}
|
||||
processor.add(createRequest);
|
||||
|
||||
|
@ -687,7 +731,8 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
.doc(new IndexRequest().source(xContentType, "id", i));
|
||||
if (erroneous == false) {
|
||||
assertEquals(RestStatus.CREATED,
|
||||
highLevelClient().index(new IndexRequest("index", "test", id).source("field", -1)).status());
|
||||
highLevelClient().index(
|
||||
new IndexRequest("index", "test", id).source("field", -1), RequestOptions.DEFAULT).status());
|
||||
}
|
||||
processor.add(updateRequest);
|
||||
}
|
||||
|
@ -739,14 +784,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
IndexRequest indexRequest = new IndexRequest(indexPattern, "type", "id#1");
|
||||
indexRequest.source("field", "value");
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(expectedIndex, indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
assertEquals("id#1", indexResponse.getId());
|
||||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest(indexPattern, "type", "id#1");
|
||||
GetResponse getResponse = highLevelClient().get(getRequest);
|
||||
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(getResponse.isExists());
|
||||
assertEquals(expectedIndex, getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
|
@ -757,21 +802,21 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
IndexRequest indexRequest = new IndexRequest("index", "type", docId);
|
||||
indexRequest.source("field", "value");
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
assertEquals(docId, indexResponse.getId());
|
||||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", docId);
|
||||
GetResponse getResponse = highLevelClient().get(getRequest);
|
||||
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(getResponse.isExists());
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
assertEquals(docId, getResponse.getId());
|
||||
}
|
||||
|
||||
assertTrue(highLevelClient().indices().exists(new GetIndexRequest().indices(indexPattern, "index")));
|
||||
assertTrue(highLevelClient().indices().exists(new GetIndexRequest().indices(indexPattern, "index"), RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
public void testParamsEncode() throws IOException {
|
||||
|
@ -781,14 +826,14 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest indexRequest = new IndexRequest("index", "type", "id");
|
||||
indexRequest.source("field", "value");
|
||||
indexRequest.routing(routing);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest);
|
||||
IndexResponse indexResponse = highLevelClient().index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals("index", indexResponse.getIndex());
|
||||
assertEquals("type", indexResponse.getType());
|
||||
assertEquals("id", indexResponse.getId());
|
||||
}
|
||||
{
|
||||
GetRequest getRequest = new GetRequest("index", "type", "id").routing(routing);
|
||||
GetResponse getResponse = highLevelClient().get(getRequest);
|
||||
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(getResponse.isExists());
|
||||
assertEquals("index", getResponse.getIndex());
|
||||
assertEquals("type", getResponse.getType());
|
||||
|
|
|
@ -60,23 +60,60 @@ public abstract class ESRestHighLevelClientTestCase extends ESRestTestCase {
|
|||
* Executes the provided request using either the sync method or its async variant, both provided as functions
|
||||
*/
|
||||
protected static <Req, Resp> Resp execute(Req request, SyncMethod<Req, Resp> syncMethod,
|
||||
AsyncMethod<Req, Resp> asyncMethod, Header... headers) throws IOException {
|
||||
AsyncMethod<Req, Resp> asyncMethod) throws IOException {
|
||||
if (randomBoolean()) {
|
||||
return syncMethod.execute(request, headers);
|
||||
return syncMethod.execute(request, RequestOptions.DEFAULT);
|
||||
} else {
|
||||
PlainActionFuture<Resp> future = PlainActionFuture.newFuture();
|
||||
asyncMethod.execute(request, future, headers);
|
||||
asyncMethod.execute(request, RequestOptions.DEFAULT, future);
|
||||
return future.actionGet();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface SyncMethod<Request, Response> {
|
||||
Response execute(Request request, Header... headers) throws IOException;
|
||||
Response execute(Request request, RequestOptions options) throws IOException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface AsyncMethod<Request, Response> {
|
||||
void execute(Request request, RequestOptions options, ActionListener<Response> listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the provided request using either the sync method or its async variant, both provided as functions
|
||||
*/
|
||||
@Deprecated
|
||||
protected static <Req, Resp> Resp execute(Req request, SyncMethod<Req, Resp> syncMethod, AsyncMethod<Req, Resp> asyncMethod,
|
||||
SyncMethodWithHeaders<Req, Resp> syncMethodWithHeaders,
|
||||
AsyncMethodWithHeaders<Req, Resp> asyncMethodWithHeaders) throws IOException {
|
||||
switch(randomIntBetween(0, 3)) {
|
||||
case 0:
|
||||
return syncMethod.execute(request, RequestOptions.DEFAULT);
|
||||
case 1:
|
||||
PlainActionFuture<Resp> future = PlainActionFuture.newFuture();
|
||||
asyncMethod.execute(request, RequestOptions.DEFAULT, future);
|
||||
return future.actionGet();
|
||||
case 2:
|
||||
return syncMethodWithHeaders.execute(request);
|
||||
case 3:
|
||||
PlainActionFuture<Resp> futureWithHeaders = PlainActionFuture.newFuture();
|
||||
asyncMethodWithHeaders.execute(request, futureWithHeaders);
|
||||
return futureWithHeaders.actionGet();
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@FunctionalInterface
|
||||
protected interface SyncMethodWithHeaders<Request, Response> {
|
||||
Response execute(Request request, Header... headers) throws IOException;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@FunctionalInterface
|
||||
protected interface AsyncMethodWithHeaders<Request, Response> {
|
||||
void execute(Request request, ActionListener<Response> listener, Header... headers);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
boolean response = execute(
|
||||
request,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync
|
||||
);
|
||||
assertTrue(response);
|
||||
|
@ -125,6 +127,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
boolean response = execute(
|
||||
request,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync
|
||||
);
|
||||
assertFalse(response);
|
||||
|
@ -143,6 +147,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
boolean response = execute(
|
||||
request,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync,
|
||||
highLevelClient().indices()::exists,
|
||||
highLevelClient().indices()::existsAsync
|
||||
);
|
||||
assertFalse(response);
|
||||
|
@ -160,7 +166,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
|
||||
|
||||
CreateIndexResponse createIndexResponse =
|
||||
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
|
||||
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync,
|
||||
highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
|
||||
assertTrue(indexExists(indexName));
|
||||
|
@ -188,7 +195,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndexRequest.mapping("type_name", mappingBuilder);
|
||||
|
||||
CreateIndexResponse createIndexResponse =
|
||||
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
|
||||
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync,
|
||||
highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
|
||||
Map<String, Object> getIndexResponse = getAsMap(indexName);
|
||||
|
@ -323,7 +331,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
putMappingRequest.source(mappingBuilder);
|
||||
|
||||
PutMappingResponse putMappingResponse =
|
||||
execute(putMappingRequest, highLevelClient().indices()::putMapping, highLevelClient().indices()::putMappingAsync);
|
||||
execute(putMappingRequest, highLevelClient().indices()::putMapping, highLevelClient().indices()::putMappingAsync,
|
||||
highLevelClient().indices()::putMapping, highLevelClient().indices()::putMappingAsync);
|
||||
assertTrue(putMappingResponse.isAcknowledged());
|
||||
|
||||
Map<String, Object> getIndexResponse = getAsMap(indexName);
|
||||
|
@ -375,7 +384,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
|
||||
DeleteIndexResponse deleteIndexResponse =
|
||||
execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync);
|
||||
execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync,
|
||||
highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync);
|
||||
assertTrue(deleteIndexResponse.isAcknowledged());
|
||||
|
||||
assertFalse(indexExists(indexName));
|
||||
|
@ -388,7 +398,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(nonExistentIndex);
|
||||
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync));
|
||||
() -> execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync,
|
||||
highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
}
|
||||
|
@ -407,6 +418,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
addAction.routing("routing").searchRouting("search_routing").filter("{\"term\":{\"year\":2016}}");
|
||||
aliasesAddRequest.addAliasAction(addAction);
|
||||
IndicesAliasesResponse aliasesAddResponse = execute(aliasesAddRequest, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync);
|
||||
assertTrue(aliasesAddResponse.isAcknowledged());
|
||||
assertThat(aliasExists(alias), equalTo(true));
|
||||
|
@ -425,6 +437,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
AliasActions removeAction = new AliasActions(AliasActions.Type.REMOVE).index(index).alias(alias);
|
||||
aliasesAddRemoveRequest.addAliasAction(removeAction);
|
||||
IndicesAliasesResponse aliasesAddRemoveResponse = execute(aliasesAddRemoveRequest, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync);
|
||||
assertTrue(aliasesAddRemoveResponse.isAcknowledged());
|
||||
assertThat(aliasExists(alias), equalTo(false));
|
||||
|
@ -436,6 +449,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
AliasActions removeIndexAction = new AliasActions(AliasActions.Type.REMOVE_INDEX).index(index);
|
||||
aliasesRemoveIndexRequest.addAliasAction(removeIndexAction);
|
||||
IndicesAliasesResponse aliasesRemoveIndexResponse = execute(aliasesRemoveIndexRequest, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync);
|
||||
assertTrue(aliasesRemoveIndexResponse.isAcknowledged());
|
||||
assertThat(aliasExists(alias), equalTo(false));
|
||||
|
@ -453,7 +467,9 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
IndicesAliasesRequest nonExistentIndexRequest = new IndicesAliasesRequest();
|
||||
nonExistentIndexRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).index(nonExistentIndex).alias(alias));
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(nonExistentIndexRequest,
|
||||
highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync));
|
||||
highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync,
|
||||
highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync));
|
||||
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
|
||||
assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]"));
|
||||
assertThat(exception.getMetadata("es.index"), hasItem(nonExistentIndex));
|
||||
|
@ -463,7 +479,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).indices(index).aliases(alias));
|
||||
mixedRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE).indices(nonExistentIndex).alias(alias));
|
||||
exception = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(mixedRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync));
|
||||
() -> execute(mixedRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync,
|
||||
highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync));
|
||||
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
|
||||
assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]"));
|
||||
assertThat(exception.getMetadata("es.index"), hasItem(nonExistentIndex));
|
||||
|
@ -475,6 +492,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
removeIndexRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).index(nonExistentIndex).alias(alias));
|
||||
removeIndexRequest.addAliasAction(new AliasActions(AliasActions.Type.REMOVE_INDEX).indices(nonExistentIndex));
|
||||
exception = expectThrows(ElasticsearchException.class, () -> execute(removeIndexRequest, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync, highLevelClient().indices()::updateAliases,
|
||||
highLevelClient().indices()::updateAliasesAsync));
|
||||
assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND));
|
||||
assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]"));
|
||||
|
@ -495,6 +513,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
OpenIndexRequest openIndexRequest = new OpenIndexRequest(index);
|
||||
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open,
|
||||
highLevelClient().indices()::openAsync, highLevelClient().indices()::open,
|
||||
highLevelClient().indices()::openAsync);
|
||||
assertTrue(openIndexResponse.isAcknowledged());
|
||||
|
||||
|
@ -508,19 +527,22 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
|
||||
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync,
|
||||
highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
|
||||
OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
|
||||
lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
|
||||
OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open,
|
||||
highLevelClient().indices()::openAsync, highLevelClient().indices()::open,
|
||||
highLevelClient().indices()::openAsync);
|
||||
assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true));
|
||||
|
||||
OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
|
||||
strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen());
|
||||
ElasticsearchException strictException = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
|
||||
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync,
|
||||
highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, strictException.status());
|
||||
}
|
||||
|
||||
|
@ -532,6 +554,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index);
|
||||
CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close,
|
||||
highLevelClient().indices()::closeAsync, highLevelClient().indices()::close,
|
||||
highLevelClient().indices()::closeAsync);
|
||||
assertTrue(closeIndexResponse.isAcknowledged());
|
||||
|
||||
|
@ -547,7 +570,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
|
||||
() -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync,
|
||||
highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
|
||||
|
@ -561,7 +585,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex(index, settings);
|
||||
RefreshRequest refreshRequest = new RefreshRequest(index);
|
||||
RefreshResponse refreshResponse =
|
||||
execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync);
|
||||
execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync,
|
||||
highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync);
|
||||
assertThat(refreshResponse.getTotalShards(), equalTo(1));
|
||||
assertThat(refreshResponse.getSuccessfulShards(), equalTo(1));
|
||||
assertThat(refreshResponse.getFailedShards(), equalTo(0));
|
||||
|
@ -572,7 +597,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertFalse(indexExists(nonExistentIndex));
|
||||
RefreshRequest refreshRequest = new RefreshRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync));
|
||||
() -> execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync,
|
||||
highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
}
|
||||
|
@ -587,7 +613,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex(index, settings);
|
||||
FlushRequest flushRequest = new FlushRequest(index);
|
||||
FlushResponse flushResponse =
|
||||
execute(flushRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync);
|
||||
execute(flushRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync,
|
||||
highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync);
|
||||
assertThat(flushResponse.getTotalShards(), equalTo(1));
|
||||
assertThat(flushResponse.getSuccessfulShards(), equalTo(1));
|
||||
assertThat(flushResponse.getFailedShards(), equalTo(0));
|
||||
|
@ -598,7 +625,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertFalse(indexExists(nonExistentIndex));
|
||||
FlushRequest flushRequest = new FlushRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(flushRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync));
|
||||
() -> execute(flushRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync,
|
||||
highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
}
|
||||
|
@ -646,7 +674,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex(index, settings);
|
||||
ClearIndicesCacheRequest clearCacheRequest = new ClearIndicesCacheRequest(index);
|
||||
ClearIndicesCacheResponse clearCacheResponse =
|
||||
execute(clearCacheRequest, highLevelClient().indices()::clearCache, highLevelClient().indices()::clearCacheAsync);
|
||||
execute(clearCacheRequest, highLevelClient().indices()::clearCache, highLevelClient().indices()::clearCacheAsync,
|
||||
highLevelClient().indices()::clearCache, highLevelClient().indices()::clearCacheAsync);
|
||||
assertThat(clearCacheResponse.getTotalShards(), equalTo(1));
|
||||
assertThat(clearCacheResponse.getSuccessfulShards(), equalTo(1));
|
||||
assertThat(clearCacheResponse.getFailedShards(), equalTo(0));
|
||||
|
@ -657,8 +686,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertFalse(indexExists(nonExistentIndex));
|
||||
ClearIndicesCacheRequest clearCacheRequest = new ClearIndicesCacheRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(clearCacheRequest, highLevelClient().indices()::clearCache,
|
||||
highLevelClient().indices()::clearCacheAsync));
|
||||
() -> execute(clearCacheRequest, highLevelClient().indices()::clearCache, highLevelClient().indices()::clearCacheAsync,
|
||||
highLevelClient().indices()::clearCache, highLevelClient().indices()::clearCacheAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
}
|
||||
|
@ -673,7 +702,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex(index, settings);
|
||||
ForceMergeRequest forceMergeRequest = new ForceMergeRequest(index);
|
||||
ForceMergeResponse forceMergeResponse =
|
||||
execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync);
|
||||
execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync,
|
||||
highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync);
|
||||
assertThat(forceMergeResponse.getTotalShards(), equalTo(1));
|
||||
assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(1));
|
||||
assertThat(forceMergeResponse.getFailedShards(), equalTo(0));
|
||||
|
@ -684,25 +714,30 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertFalse(indexExists(nonExistentIndex));
|
||||
ForceMergeRequest forceMergeRequest = new ForceMergeRequest(nonExistentIndex);
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||
() -> execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync));
|
||||
() -> execute(forceMergeRequest, highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync,
|
||||
highLevelClient().indices()::forceMerge, highLevelClient().indices()::forceMergeAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
}
|
||||
}
|
||||
|
||||
public void testExistsAlias() throws IOException {
|
||||
GetAliasesRequest getAliasesRequest = new GetAliasesRequest("alias");
|
||||
assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync,
|
||||
highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
|
||||
createIndex("index", Settings.EMPTY);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/_alias/alias");
|
||||
assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync,
|
||||
highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
|
||||
GetAliasesRequest getAliasesRequest2 = new GetAliasesRequest();
|
||||
getAliasesRequest2.aliases("alias");
|
||||
getAliasesRequest2.indices("index");
|
||||
assertTrue(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
assertTrue(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync,
|
||||
highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
getAliasesRequest2.indices("does_not_exist");
|
||||
assertFalse(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
assertFalse(execute(getAliasesRequest2, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync,
|
||||
highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -722,7 +757,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
.putNull("index.routing.allocation.require._name")
|
||||
.build();
|
||||
resizeRequest.setTargetIndex(new CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
|
||||
ResizeResponse resizeResponse = highLevelClient().indices().shrink(resizeRequest);
|
||||
ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::shrink,
|
||||
highLevelClient().indices()::shrinkAsync, highLevelClient().indices()::shrink, highLevelClient().indices()::shrinkAsync);
|
||||
assertTrue(resizeResponse.isAcknowledged());
|
||||
assertTrue(resizeResponse.isShardsAcknowledged());
|
||||
Map<String, Object> getIndexResponse = getAsMap("target");
|
||||
|
@ -744,7 +780,8 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
resizeRequest.setResizeType(ResizeType.SPLIT);
|
||||
Settings targetSettings = Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build();
|
||||
resizeRequest.setTargetIndex(new CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
|
||||
ResizeResponse resizeResponse = highLevelClient().indices().split(resizeRequest);
|
||||
ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::split, highLevelClient().indices()::splitAsync,
|
||||
highLevelClient().indices()::split, highLevelClient().indices()::splitAsync);
|
||||
assertTrue(resizeResponse.isAcknowledged());
|
||||
assertTrue(resizeResponse.isShardsAcknowledged());
|
||||
Map<String, Object> getIndexResponse = getAsMap("target");
|
||||
|
@ -757,12 +794,13 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
public void testRollover() throws IOException {
|
||||
highLevelClient().indices().create(new CreateIndexRequest("test").alias(new Alias("alias")));
|
||||
highLevelClient().indices().create(new CreateIndexRequest("test").alias(new Alias("alias")), RequestOptions.DEFAULT);
|
||||
RolloverRequest rolloverRequest = new RolloverRequest("alias", "test_new");
|
||||
rolloverRequest.addMaxIndexDocsCondition(1);
|
||||
|
||||
{
|
||||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync);
|
||||
assertFalse(rolloverResponse.isRolledOver());
|
||||
assertFalse(rolloverResponse.isDryRun());
|
||||
|
@ -773,15 +811,16 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertEquals("test_new", rolloverResponse.getNewIndex());
|
||||
}
|
||||
|
||||
highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value"));
|
||||
highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value"), RequestOptions.DEFAULT);
|
||||
highLevelClient().index(new IndexRequest("test", "type", "2").source("field", "value")
|
||||
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL));
|
||||
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL), RequestOptions.DEFAULT);
|
||||
//without the refresh the rollover may not happen as the number of docs seen may be off
|
||||
|
||||
{
|
||||
rolloverRequest.addMaxIndexAgeCondition(new TimeValue(1));
|
||||
rolloverRequest.dryRun(true);
|
||||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync);
|
||||
assertFalse(rolloverResponse.isRolledOver());
|
||||
assertTrue(rolloverResponse.isDryRun());
|
||||
|
@ -796,6 +835,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
rolloverRequest.dryRun(false);
|
||||
rolloverRequest.addMaxIndexSizeCondition(new ByteSizeValue(1, ByteSizeUnit.MB));
|
||||
RolloverResponse rolloverResponse = execute(rolloverRequest, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync, highLevelClient().indices()::rollover,
|
||||
highLevelClient().indices()::rolloverAsync);
|
||||
assertTrue(rolloverResponse.isRolledOver());
|
||||
assertFalse(rolloverResponse.isDryRun());
|
||||
|
@ -830,6 +870,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateSettingsRequest dynamicSettingRequest = new UpdateSettingsRequest();
|
||||
dynamicSettingRequest.settings(Settings.builder().put(dynamicSettingKey, dynamicSettingValue).build());
|
||||
UpdateSettingsResponse response = execute(dynamicSettingRequest, highLevelClient().indices()::putSettings,
|
||||
highLevelClient().indices()::putSettingsAsync, highLevelClient().indices()::putSettings,
|
||||
highLevelClient().indices()::putSettingsAsync);
|
||||
|
||||
assertTrue(response.isAcknowledged());
|
||||
|
@ -840,6 +881,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateSettingsRequest staticSettingRequest = new UpdateSettingsRequest();
|
||||
staticSettingRequest.settings(Settings.builder().put(staticSettingKey, staticSettingValue).build());
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(staticSettingRequest,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
|
||||
assertThat(exception.getMessage(),
|
||||
startsWith("Elasticsearch exception [type=illegal_argument_exception, "
|
||||
|
@ -850,6 +892,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
closeIndex(index);
|
||||
response = execute(staticSettingRequest, highLevelClient().indices()::putSettings,
|
||||
highLevelClient().indices()::putSettingsAsync, highLevelClient().indices()::putSettings,
|
||||
highLevelClient().indices()::putSettingsAsync);
|
||||
assertTrue(response.isAcknowledged());
|
||||
openIndex(index);
|
||||
|
@ -860,6 +903,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateSettingsRequest unmodifiableSettingRequest = new UpdateSettingsRequest();
|
||||
unmodifiableSettingRequest.settings(Settings.builder().put(unmodifiableSettingKey, unmodifiableSettingValue).build());
|
||||
exception = expectThrows(ElasticsearchException.class, () -> execute(unmodifiableSettingRequest,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
|
||||
assertThat(exception.getMessage(), startsWith(
|
||||
"Elasticsearch exception [type=illegal_argument_exception, "
|
||||
|
@ -887,12 +931,14 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
indexUpdateSettingsRequest.settings(Settings.builder().put(setting, value).build());
|
||||
|
||||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]"));
|
||||
|
||||
createIndex(index, Settings.EMPTY);
|
||||
exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync,
|
||||
highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
|
||||
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
|
||||
assertThat(exception.getMessage(), equalTo(
|
||||
|
|
|
@ -28,12 +28,12 @@ import java.util.Map;
|
|||
public class PingAndInfoIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
public void testPing() throws IOException {
|
||||
assertTrue(highLevelClient().ping());
|
||||
assertTrue(highLevelClient().ping(RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testInfo() throws IOException {
|
||||
MainResponse info = highLevelClient().info();
|
||||
MainResponse info = highLevelClient().info(RequestOptions.DEFAULT);
|
||||
// compare with what the low level client outputs
|
||||
Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(HttpGet.METHOD_NAME, "/"));
|
||||
assertEquals(infoAsMap.get("cluster_name"), info.getClusterName().value());
|
||||
|
|
|
@ -82,8 +82,8 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
RankEvalSpec spec = new RankEvalSpec(specifications, metric);
|
||||
|
||||
RankEvalRequest rankEvalRequest = new RankEvalRequest(spec, new String[] { "index", "index2" });
|
||||
RankEvalResponse response = execute(rankEvalRequest, highLevelClient()::rankEval,
|
||||
highLevelClient()::rankEvalAsync);
|
||||
RankEvalResponse response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync,
|
||||
highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
|
||||
// the expected Prec@ for the first query is 5/7 and the expected Prec@ for the second is 1/7, divided by 2 to get the average
|
||||
double expectedPrecision = (1.0 / 7.0 + 5.0 / 7.0) / 2.0;
|
||||
assertEquals(expectedPrecision, response.getEvaluationResult(), Double.MIN_VALUE);
|
||||
|
@ -117,7 +117,8 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
// now try this when test2 is closed
|
||||
client().performRequest("POST", "index2/_close", Collections.emptyMap());
|
||||
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
|
||||
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
|
||||
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync,
|
||||
highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
|
||||
}
|
||||
|
||||
private static List<RatedDocument> createRelevant(String indexName, String... docs) {
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.http.entity.ByteArrayEntity;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.DocWriteRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
|
||||
|
@ -1587,6 +1589,23 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
assertEquals(expectedParams, request.getParameters());
|
||||
}
|
||||
|
||||
public void testCancelTasks() {
|
||||
CancelTasksRequest request = new CancelTasksRequest();
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
TaskId taskId = new TaskId(randomAlphaOfLength(5), randomNonNegativeLong());
|
||||
TaskId parentTaskId = new TaskId(randomAlphaOfLength(5), randomNonNegativeLong());
|
||||
request.setTaskId(taskId);
|
||||
request.setParentTaskId(parentTaskId);
|
||||
expectedParams.put("task_id", taskId.toString());
|
||||
expectedParams.put("parent_task_id", parentTaskId.toString());
|
||||
Request httpRequest = RequestConverters.cancelTasks(request);
|
||||
assertThat(httpRequest, notNullValue());
|
||||
assertThat(httpRequest.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
assertThat(httpRequest.getEntity(), nullValue());
|
||||
assertThat(httpRequest.getEndpoint(), equalTo("/_tasks/_cancel"));
|
||||
assertThat(httpRequest.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testListTasks() {
|
||||
{
|
||||
ListTasksRequest request = new ListTasksRequest();
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
|
@ -28,10 +27,7 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.RequestLine;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
|
@ -77,9 +73,6 @@ import org.elasticsearch.search.suggest.Suggest;
|
|||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.InternalAggregationTestCase;
|
||||
import org.junit.Before;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.internal.matchers.ArrayEquals;
|
||||
import org.mockito.internal.matchers.VarargMatcher;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
@ -124,25 +117,22 @@ public class RestHighLevelClientTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testPingSuccessful() throws IOException {
|
||||
Header[] headers = randomHeaders(random(), "Header");
|
||||
Response response = mock(Response.class);
|
||||
when(response.getStatusLine()).thenReturn(newStatusLine(RestStatus.OK));
|
||||
when(restClient.performRequest(any(Request.class))).thenReturn(response);
|
||||
assertTrue(restHighLevelClient.ping(headers));
|
||||
assertTrue(restHighLevelClient.ping(RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
public void testPing404NotFound() throws IOException {
|
||||
Header[] headers = randomHeaders(random(), "Header");
|
||||
Response response = mock(Response.class);
|
||||
when(response.getStatusLine()).thenReturn(newStatusLine(RestStatus.NOT_FOUND));
|
||||
when(restClient.performRequest(any(Request.class))).thenReturn(response);
|
||||
assertFalse(restHighLevelClient.ping(headers));
|
||||
assertFalse(restHighLevelClient.ping(RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
public void testPingSocketTimeout() throws IOException {
|
||||
Header[] headers = randomHeaders(random(), "Header");
|
||||
when(restClient.performRequest(any(Request.class))).thenThrow(new SocketTimeoutException());
|
||||
expectThrows(SocketTimeoutException.class, () -> restHighLevelClient.ping(headers));
|
||||
expectThrows(SocketTimeoutException.class, () -> restHighLevelClient.ping(RequestOptions.DEFAULT));
|
||||
}
|
||||
|
||||
public void testInfo() throws IOException {
|
||||
|
@ -150,18 +140,17 @@ public class RestHighLevelClientTests extends ESTestCase {
|
|||
MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid",
|
||||
Build.CURRENT);
|
||||
mockResponse(testInfo);
|
||||
MainResponse receivedInfo = restHighLevelClient.info(headers);
|
||||
MainResponse receivedInfo = restHighLevelClient.info(RequestOptions.DEFAULT);
|
||||
assertEquals(testInfo, receivedInfo);
|
||||
}
|
||||
|
||||
public void testSearchScroll() throws IOException {
|
||||
Header[] headers = randomHeaders(random(), "Header");
|
||||
SearchResponse mockSearchResponse = new SearchResponse(new SearchResponseSections(SearchHits.empty(), InternalAggregations.EMPTY,
|
||||
null, false, false, null, 1), randomAlphaOfLengthBetween(5, 10), 5, 5, 0, 100, ShardSearchFailure.EMPTY_ARRAY,
|
||||
SearchResponse.Clusters.EMPTY);
|
||||
mockResponse(mockSearchResponse);
|
||||
SearchResponse searchResponse = restHighLevelClient.searchScroll(new SearchScrollRequest(randomAlphaOfLengthBetween(5, 10)),
|
||||
headers);
|
||||
SearchResponse searchResponse = restHighLevelClient.searchScroll(
|
||||
new SearchScrollRequest(randomAlphaOfLengthBetween(5, 10)), RequestOptions.DEFAULT);
|
||||
assertEquals(mockSearchResponse.getScrollId(), searchResponse.getScrollId());
|
||||
assertEquals(0, searchResponse.getHits().totalHits);
|
||||
assertEquals(5, searchResponse.getTotalShards());
|
||||
|
@ -170,12 +159,11 @@ public class RestHighLevelClientTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testClearScroll() throws IOException {
|
||||
Header[] headers = randomHeaders(random(), "Header");
|
||||
ClearScrollResponse mockClearScrollResponse = new ClearScrollResponse(randomBoolean(), randomIntBetween(0, Integer.MAX_VALUE));
|
||||
mockResponse(mockClearScrollResponse);
|
||||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
|
||||
clearScrollRequest.addScrollId(randomAlphaOfLengthBetween(5, 10));
|
||||
ClearScrollResponse clearScrollResponse = restHighLevelClient.clearScroll(clearScrollRequest, headers);
|
||||
ClearScrollResponse clearScrollResponse = restHighLevelClient.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(mockClearScrollResponse.isSucceeded(), clearScrollResponse.isSucceeded());
|
||||
assertEquals(mockClearScrollResponse.getNumFreed(), clearScrollResponse.getNumFreed());
|
||||
}
|
||||
|
|
|
@ -164,7 +164,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
public void testSearchMatchQuery() throws IOException {
|
||||
SearchRequest searchRequest = new SearchRequest("index");
|
||||
searchRequest.source(new SearchSourceBuilder().query(new MatchQueryBuilder("num", 10)));
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getAggregations());
|
||||
assertNull(searchResponse.getSuggest());
|
||||
|
@ -190,7 +191,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.aggregation(new TermsAggregationBuilder("agg1", ValueType.STRING).field("type.keyword"));
|
||||
searchSourceBuilder.size(0);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getSuggest());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -216,7 +218,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync));
|
||||
() -> execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync));
|
||||
assertEquals(RestStatus.BAD_REQUEST, exception.status());
|
||||
}
|
||||
|
||||
|
@ -226,7 +229,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
.addRange("first", 0, 30).addRange("second", 31, 200));
|
||||
searchSourceBuilder.size(0);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getSuggest());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -257,7 +261,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.aggregation(agg);
|
||||
searchSourceBuilder.size(0);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getSuggest());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -308,7 +313,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.aggregation(new MatrixStatsAggregationBuilder("agg1").fields(Arrays.asList("num", "num2")));
|
||||
searchSourceBuilder.size(0);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getSuggest());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -397,7 +403,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
SearchRequest searchRequest = new SearchRequest(indexName);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getSuggest());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -437,7 +444,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.size(0);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
assertSearchHeader(searchResponse);
|
||||
assertNull(searchResponse.getAggregations());
|
||||
assertEquals(Collections.emptyMap(), searchResponse.getProfileResults());
|
||||
|
@ -469,7 +477,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
SearchRequest searchRequest = new SearchRequest("test").source(SearchSourceBuilder.searchSource()
|
||||
.scriptField("result", new Script("null")));
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchHit searchHit = searchResponse.getHits().getAt(0);
|
||||
List<Object> values = searchHit.getFields().get("result").getValues();
|
||||
assertNotNull(values);
|
||||
|
@ -479,7 +488,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
SearchRequest searchRequest = new SearchRequest("test").source(SearchSourceBuilder.searchSource()
|
||||
.scriptField("result", new Script("new HashMap()")));
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchHit searchHit = searchResponse.getHits().getAt(0);
|
||||
List<Object> values = searchHit.getFields().get("result").getValues();
|
||||
assertNotNull(values);
|
||||
|
@ -491,7 +501,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
SearchRequest searchRequest = new SearchRequest("test").source(SearchSourceBuilder.searchSource()
|
||||
.scriptField("result", new Script("new String[]{}")));
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchHit searchHit = searchResponse.getHits().getAt(0);
|
||||
List<Object> values = searchHit.getFields().get("result").getValues();
|
||||
assertNotNull(values);
|
||||
|
@ -513,7 +524,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(35).sort("field", SortOrder.ASC);
|
||||
SearchRequest searchRequest = new SearchRequest("test").scroll(TimeValue.timeValueMinutes(2)).source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync,
|
||||
highLevelClient()::search, highLevelClient()::searchAsync);
|
||||
|
||||
try {
|
||||
long counter = 0;
|
||||
|
@ -525,6 +537,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)),
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync,
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync);
|
||||
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
|
||||
|
@ -534,6 +547,7 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
searchResponse = execute(new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2)),
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync,
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync);
|
||||
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
|
||||
|
@ -545,14 +559,14 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
|
||||
clearScrollRequest.addScrollId(searchResponse.getScrollId());
|
||||
ClearScrollResponse clearScrollResponse = execute(clearScrollRequest,
|
||||
// Not using a method reference to work around https://bugs.eclipse.org/bugs/show_bug.cgi?id=517951
|
||||
(request, headers) -> highLevelClient().clearScroll(request, headers),
|
||||
(request, listener, headers) -> highLevelClient().clearScrollAsync(request, listener, headers));
|
||||
highLevelClient()::clearScroll, highLevelClient()::clearScrollAsync,
|
||||
highLevelClient()::clearScroll, highLevelClient()::clearScrollAsync);
|
||||
assertThat(clearScrollResponse.getNumFreed(), greaterThan(0));
|
||||
assertTrue(clearScrollResponse.isSucceeded());
|
||||
|
||||
SearchScrollRequest scrollRequest = new SearchScrollRequest(searchResponse.getScrollId()).scroll(TimeValue.timeValueMinutes(2));
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> execute(scrollRequest,
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync,
|
||||
highLevelClient()::searchScroll, highLevelClient()::searchScrollAsync));
|
||||
assertEquals(RestStatus.NOT_FOUND, exception.status());
|
||||
assertThat(exception.getRootCause(), instanceOf(ElasticsearchException.class));
|
||||
|
@ -574,7 +588,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
multiSearchRequest.add(searchRequest3);
|
||||
|
||||
MultiSearchResponse multiSearchResponse =
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync,
|
||||
highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
|
||||
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
|
||||
|
||||
|
@ -616,7 +631,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
multiSearchRequest.add(searchRequest3);
|
||||
|
||||
MultiSearchResponse multiSearchResponse =
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync,
|
||||
highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
|
||||
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
|
||||
|
||||
|
@ -664,7 +680,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
multiSearchRequest.add(searchRequest3);
|
||||
|
||||
MultiSearchResponse multiSearchResponse =
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync,
|
||||
highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
|
||||
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(3));
|
||||
|
||||
|
@ -727,7 +744,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
multiSearchRequest.add(searchRequest2);
|
||||
|
||||
MultiSearchResponse multiSearchResponse =
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
execute(multiSearchRequest, highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync,
|
||||
highLevelClient()::multiSearch, highLevelClient()::multiSearchAsync);
|
||||
assertThat(multiSearchResponse.getTook().millis(), Matchers.greaterThanOrEqualTo(0L));
|
||||
assertThat(multiSearchResponse.getResponses().length, Matchers.equalTo(2));
|
||||
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
|
||||
import org.elasticsearch.tasks.TaskId;
|
||||
import org.elasticsearch.tasks.TaskInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -58,4 +61,26 @@ public class TasksIT extends ESRestHighLevelClientTestCase {
|
|||
assertTrue("List tasks were not found", listTasksFound);
|
||||
}
|
||||
|
||||
public void testCancelTasks() throws IOException {
|
||||
ListTasksRequest listRequest = new ListTasksRequest();
|
||||
ListTasksResponse listResponse = execute(
|
||||
listRequest,
|
||||
highLevelClient().tasks()::list,
|
||||
highLevelClient().tasks()::listAsync
|
||||
);
|
||||
// in this case, probably no task will actually be cancelled.
|
||||
// this is ok, that case is covered in TasksIT.testTasksCancellation
|
||||
TaskInfo firstTask = listResponse.getTasks().get(0);
|
||||
String node = listResponse.getPerNodeTasks().keySet().iterator().next();
|
||||
|
||||
CancelTasksRequest cancelTasksRequest = new CancelTasksRequest();
|
||||
cancelTasksRequest.setTaskId(new TaskId(node, firstTask.getId()));
|
||||
cancelTasksRequest.setReason("testreason");
|
||||
CancelTasksResponse response = execute(cancelTasksRequest,
|
||||
highLevelClient().tasks()::cancel,
|
||||
highLevelClient().tasks()::cancelAsync);
|
||||
// Since the task may or may not have been cancelled, assert that we received a response only
|
||||
// The actual testing of task cancellation is covered by TasksIT.testTasksCancellation
|
||||
assertThat(response, notNullValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.elasticsearch.action.update.UpdateRequest;
|
|||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -72,13 +73,12 @@ import java.util.Map;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
/**
|
||||
* This class is used to generate the Java CRUD API documentation.
|
||||
|
@ -112,7 +112,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1")
|
||||
.source(jsonMap); // <1>
|
||||
//end::index-request-map
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(indexResponse.getResult(), DocWriteResponse.Result.CREATED);
|
||||
}
|
||||
{
|
||||
|
@ -128,7 +128,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1")
|
||||
.source(builder); // <1>
|
||||
//end::index-request-xcontent
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(indexResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
}
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
"postDate", new Date(),
|
||||
"message", "trying out Elasticsearch"); // <1>
|
||||
//end::index-request-shortcut
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(indexResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
}
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//end::index-request-string
|
||||
|
||||
// tag::index-execute
|
||||
IndexResponse indexResponse = client.index(request);
|
||||
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
|
||||
// end::index-execute
|
||||
assertEquals(indexResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
|
||||
|
@ -214,7 +214,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.source("field", "value")
|
||||
.version(1);
|
||||
try {
|
||||
IndexResponse response = client.index(request);
|
||||
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
|
||||
} catch(ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.CONFLICT) {
|
||||
// <1>
|
||||
|
@ -228,7 +228,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.source("field", "value")
|
||||
.opType(DocWriteRequest.OpType.CREATE);
|
||||
try {
|
||||
IndexResponse response = client.index(request);
|
||||
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
|
||||
} catch(ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.CONFLICT) {
|
||||
// <1>
|
||||
|
@ -257,7 +257,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::index-execute-async
|
||||
client.indexAsync(request, listener); // <1>
|
||||
client.indexAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -268,7 +268,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
{
|
||||
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1").source("field", 0);
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertSame(indexResponse.status(), RestStatus.CREATED);
|
||||
|
||||
Request request = new Request("POST", "/_scripts/increment-field");
|
||||
|
@ -297,7 +297,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
"ctx._source.field += params.count", parameters); // <2>
|
||||
request.script(inline); // <3>
|
||||
//end::update-request-with-inline-script
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
assertEquals(4, updateResponse.getGetResult().getSource().get("field"));
|
||||
|
||||
|
@ -307,7 +307,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
new Script(ScriptType.STORED, null, "increment-field", parameters); // <1>
|
||||
request.script(stored); // <2>
|
||||
//end::update-request-with-stored-script
|
||||
updateResponse = client.update(request);
|
||||
updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
assertEquals(8, updateResponse.getGetResult().getSource().get("field"));
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateRequest request = new UpdateRequest("posts", "doc", "1")
|
||||
.doc(jsonMap); // <1>
|
||||
//end::update-request-with-doc-as-map
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
}
|
||||
{
|
||||
|
@ -334,7 +334,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateRequest request = new UpdateRequest("posts", "doc", "1")
|
||||
.doc(builder); // <1>
|
||||
//end::update-request-with-doc-as-xcontent
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
}
|
||||
{
|
||||
|
@ -343,7 +343,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.doc("updated", new Date(),
|
||||
"reason", "daily update"); // <1>
|
||||
//end::update-request-shortcut
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
}
|
||||
{
|
||||
|
@ -357,7 +357,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//end::update-request-with-doc-as-string
|
||||
request.fetchSource(true);
|
||||
// tag::update-execute
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
// end::update-execute
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
|
||||
|
@ -406,7 +406,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
UpdateRequest request = new UpdateRequest("posts", "type", "does_not_exist")
|
||||
.doc("field", "value");
|
||||
try {
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -420,7 +420,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.doc("field", "value")
|
||||
.version(1);
|
||||
try {
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
} catch(ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.CONFLICT) {
|
||||
// <1>
|
||||
|
@ -433,7 +433,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//tag::update-request-no-source
|
||||
request.fetchSource(true); // <1>
|
||||
//end::update-request-no-source
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
assertNotNull(updateResponse.getGetResult());
|
||||
assertEquals(3, updateResponse.getGetResult().sourceAsMap().size());
|
||||
|
@ -445,7 +445,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
String[] excludes = Strings.EMPTY_ARRAY;
|
||||
request.fetchSource(new FetchSourceContext(true, includes, excludes)); // <1>
|
||||
//end::update-request-source-include
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
Map<String, Object> sourceAsMap = updateResponse.getGetResult().sourceAsMap();
|
||||
assertEquals(2, sourceAsMap.size());
|
||||
|
@ -459,7 +459,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
String[] excludes = new String[]{"updated"};
|
||||
request.fetchSource(new FetchSourceContext(true, includes, excludes)); // <1>
|
||||
//end::update-request-source-exclude
|
||||
UpdateResponse updateResponse = client.update(request);
|
||||
UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT);
|
||||
assertEquals(updateResponse.getResult(), DocWriteResponse.Result.UPDATED);
|
||||
Map<String, Object> sourceAsMap = updateResponse.getGetResult().sourceAsMap();
|
||||
assertEquals(2, sourceAsMap.size());
|
||||
|
@ -525,7 +525,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::update-execute-async
|
||||
client.updateAsync(request, listener); // <1>
|
||||
client.updateAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::update-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -537,7 +537,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
{
|
||||
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1").source("field", "value");
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertSame(indexResponse.status(), RestStatus.CREATED);
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::delete-request
|
||||
|
||||
// tag::delete-execute
|
||||
DeleteResponse deleteResponse = client.delete(request);
|
||||
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
|
||||
// end::delete-execute
|
||||
assertSame(deleteResponse.getResult(), DocWriteResponse.Result.DELETED);
|
||||
|
||||
|
@ -595,7 +595,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
// tag::delete-notfound
|
||||
DeleteRequest request = new DeleteRequest("posts", "doc", "does_not_exist");
|
||||
DeleteResponse deleteResponse = client.delete(request);
|
||||
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
|
||||
if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
|
||||
// <1>
|
||||
}
|
||||
|
@ -603,13 +603,14 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
{
|
||||
IndexResponse indexResponse = client.index(new IndexRequest("posts", "doc", "1").source("field", "value"));
|
||||
IndexResponse indexResponse = client.index(new IndexRequest("posts", "doc", "1").source("field", "value")
|
||||
, RequestOptions.DEFAULT);
|
||||
assertSame(indexResponse.status(), RestStatus.CREATED);
|
||||
|
||||
// tag::delete-conflict
|
||||
try {
|
||||
DeleteRequest request = new DeleteRequest("posts", "doc", "1").version(2);
|
||||
DeleteResponse deleteResponse = client.delete(request);
|
||||
DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.CONFLICT) {
|
||||
// <1>
|
||||
|
@ -618,7 +619,8 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::delete-conflict
|
||||
}
|
||||
{
|
||||
IndexResponse indexResponse = client.index(new IndexRequest("posts", "doc", "async").source("field", "value"));
|
||||
IndexResponse indexResponse = client.index(new IndexRequest("posts", "doc", "async").source("field", "value"),
|
||||
RequestOptions.DEFAULT);
|
||||
assertSame(indexResponse.status(), RestStatus.CREATED);
|
||||
|
||||
DeleteRequest request = new DeleteRequest("posts", "doc", "async");
|
||||
|
@ -642,7 +644,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::delete-execute-async
|
||||
client.deleteAsync(request, listener); // <1>
|
||||
client.deleteAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::delete-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -662,7 +664,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.source(XContentType.JSON,"field", "baz"));
|
||||
// end::bulk-request
|
||||
// tag::bulk-execute
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
// end::bulk-execute
|
||||
assertSame(bulkResponse.status(), RestStatus.OK);
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
|
@ -676,7 +678,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new IndexRequest("posts", "doc", "4") // <3>
|
||||
.source(XContentType.JSON,"field", "baz"));
|
||||
// end::bulk-request-with-mixed-operations
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
assertSame(bulkResponse.status(), RestStatus.OK);
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
|
||||
|
@ -775,7 +777,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.source("user", "kimchy",
|
||||
"postDate", new Date(),
|
||||
"message", "trying out Elasticsearch");
|
||||
IndexResponse indexResponse = client.index(indexRequest);
|
||||
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
|
||||
assertEquals(indexResponse.getResult(), DocWriteResponse.Result.CREATED);
|
||||
}
|
||||
{
|
||||
|
@ -787,7 +789,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//end::get-request
|
||||
|
||||
//tag::get-execute
|
||||
GetResponse getResponse = client.get(getRequest);
|
||||
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
|
||||
//end::get-execute
|
||||
assertTrue(getResponse.isExists());
|
||||
assertEquals(3, getResponse.getSourceAsMap().size());
|
||||
|
@ -810,7 +812,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//tag::get-request-no-source
|
||||
request.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE); // <1>
|
||||
//end::get-request-no-source
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
assertNull(getResponse.getSourceInternal());
|
||||
}
|
||||
{
|
||||
|
@ -822,7 +824,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
new FetchSourceContext(true, includes, excludes);
|
||||
request.fetchSourceContext(fetchSourceContext); // <1>
|
||||
//end::get-request-source-include
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
Map<String, Object> sourceAsMap = getResponse.getSourceAsMap();
|
||||
assertEquals(2, sourceAsMap.size());
|
||||
assertEquals("trying out Elasticsearch", sourceAsMap.get("message"));
|
||||
|
@ -837,7 +839,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
new FetchSourceContext(true, includes, excludes);
|
||||
request.fetchSourceContext(fetchSourceContext); // <1>
|
||||
//end::get-request-source-exclude
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
Map<String, Object> sourceAsMap = getResponse.getSourceAsMap();
|
||||
assertEquals(2, sourceAsMap.size());
|
||||
assertEquals("kimchy", sourceAsMap.get("user"));
|
||||
|
@ -847,7 +849,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
GetRequest request = new GetRequest("posts", "doc", "1");
|
||||
//tag::get-request-stored
|
||||
request.storedFields("message"); // <1>
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
String message = getResponse.getField("message").getValue(); // <2>
|
||||
//end::get-request-stored
|
||||
assertEquals("trying out Elasticsearch", message);
|
||||
|
@ -897,7 +899,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
//tag::get-execute-async
|
||||
client.getAsync(request, listener); // <1>
|
||||
client.getAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
//end::get-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -906,7 +908,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//tag::get-indexnotfound
|
||||
GetRequest request = new GetRequest("does_not_exist", "doc", "1");
|
||||
try {
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -918,7 +920,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// tag::get-conflict
|
||||
try {
|
||||
GetRequest request = new GetRequest("posts", "doc", "1").version(2);
|
||||
GetResponse getResponse = client.get(request);
|
||||
GetResponse getResponse = client.get(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.CONFLICT) {
|
||||
// <1>
|
||||
|
@ -940,7 +942,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::exists-request
|
||||
{
|
||||
// tag::exists-execute
|
||||
boolean exists = client.exists(getRequest);
|
||||
boolean exists = client.exists(getRequest, RequestOptions.DEFAULT);
|
||||
// end::exists-execute
|
||||
assertFalse(exists);
|
||||
}
|
||||
|
@ -964,7 +966,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::exists-execute-async
|
||||
client.existsAsync(getRequest, listener); // <1>
|
||||
client.existsAsync(getRequest, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::exists-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1091,7 +1093,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
source.put("baz", "val3");
|
||||
client.index(new IndexRequest("index", "type", "example_id")
|
||||
.source(source)
|
||||
.setRefreshPolicy(RefreshPolicy.IMMEDIATE));
|
||||
.setRefreshPolicy(RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT);
|
||||
|
||||
{
|
||||
// tag::multi-get-request
|
||||
|
@ -1120,7 +1122,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::multi-get-request-top-level-extras
|
||||
|
||||
// tag::multi-get-execute
|
||||
MultiGetResponse response = client.multiGet(request);
|
||||
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
|
||||
// end::multi-get-execute
|
||||
|
||||
// tag::multi-get-response
|
||||
|
@ -1184,7 +1186,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new MultiGetRequest.Item("index", "type", "example_id")
|
||||
.fetchSourceContext(FetchSourceContext.DO_NOT_FETCH_SOURCE)); // <1>
|
||||
// end::multi-get-request-no-source
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request));
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
|
||||
assertNull(item.getResponse().getSource());
|
||||
}
|
||||
{
|
||||
|
@ -1197,7 +1199,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new MultiGetRequest.Item("index", "type", "example_id")
|
||||
.fetchSourceContext(fetchSourceContext)); // <1>
|
||||
// end::multi-get-request-source-include
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request));
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
|
||||
assertThat(item.getResponse().getSource(), hasEntry("foo", "val1"));
|
||||
assertThat(item.getResponse().getSource(), hasEntry("bar", "val2"));
|
||||
assertThat(item.getResponse().getSource(), not(hasKey("baz")));
|
||||
|
@ -1212,7 +1214,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new MultiGetRequest.Item("index", "type", "example_id")
|
||||
.fetchSourceContext(fetchSourceContext)); // <1>
|
||||
// end::multi-get-request-source-exclude
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request));
|
||||
MultiGetItemResponse item = unwrapAndAssertExample(client.multiGet(request, RequestOptions.DEFAULT));
|
||||
assertThat(item.getResponse().getSource(), not(hasKey("foo")));
|
||||
assertThat(item.getResponse().getSource(), not(hasKey("bar")));
|
||||
assertThat(item.getResponse().getSource(), hasEntry("baz", "val3"));
|
||||
|
@ -1222,7 +1224,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// tag::multi-get-request-stored
|
||||
request.add(new MultiGetRequest.Item("index", "type", "example_id")
|
||||
.storedFields("foo")); // <1>
|
||||
MultiGetResponse response = client.multiGet(request);
|
||||
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
|
||||
MultiGetItemResponse item = response.getResponses()[0];
|
||||
String value = item.getResponse().getField("foo").getValue(); // <2>
|
||||
// end::multi-get-request-stored
|
||||
|
@ -1234,7 +1236,7 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
MultiGetRequest request = new MultiGetRequest();
|
||||
request.add(new MultiGetRequest.Item("index", "type", "example_id")
|
||||
.version(1000L));
|
||||
MultiGetResponse response = client.multiGet(request);
|
||||
MultiGetResponse response = client.multiGet(request, RequestOptions.DEFAULT);
|
||||
MultiGetItemResponse item = response.getResponses()[0];
|
||||
assertNull(item.getResponse()); // <1>
|
||||
Exception e = item.getFailure().getFailure(); // <2>
|
||||
|
|
|
@ -23,27 +23,19 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.action.LatchedActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
|
||||
import org.elasticsearch.action.ingest.GetPipelineRequest;
|
||||
import org.elasticsearch.action.ingest.GetPipelineResponse;
|
||||
import org.elasticsearch.action.ingest.PutPipelineRequest;
|
||||
import org.elasticsearch.action.ingest.DeletePipelineRequest;
|
||||
import org.elasticsearch.action.ingest.WritePipelineResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.indices.recovery.RecoverySettings;
|
||||
import org.elasticsearch.ingest.PipelineConfiguration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -134,7 +126,7 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::put-settings-request-masterTimeout
|
||||
|
||||
// tag::put-settings-execute
|
||||
ClusterUpdateSettingsResponse response = client.cluster().putSettings(request);
|
||||
ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, RequestOptions.DEFAULT);
|
||||
// end::put-settings-execute
|
||||
|
||||
// tag::put-settings-response
|
||||
|
@ -150,7 +142,7 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
request.transientSettings(Settings.builder().putNull(transientSettingKey).build()); // <1>
|
||||
// tag::put-settings-request-reset-transient
|
||||
request.persistentSettings(Settings.builder().putNull(persistentSettingKey));
|
||||
ClusterUpdateSettingsResponse resetResponse = client.cluster().putSettings(request);
|
||||
ClusterUpdateSettingsResponse resetResponse = client.cluster().putSettings(request, RequestOptions.DEFAULT);
|
||||
|
||||
assertTrue(resetResponse.isAcknowledged());
|
||||
}
|
||||
|
@ -180,10 +172,11 @@ public class ClusterClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::put-settings-execute-async
|
||||
client.cluster().putSettingsAsync(request, listener); // <1>
|
||||
client.cluster().putSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::put-settings-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ import org.elasticsearch.action.support.ActiveShardCount;
|
|||
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.SyncedFlushResponse;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
|
@ -111,7 +112,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -130,7 +131,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::indices-exists-request-optionals
|
||||
|
||||
// tag::indices-exists-response
|
||||
boolean exists = client.indices().exists(request);
|
||||
boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);
|
||||
// end::indices-exists-response
|
||||
assertTrue(exists);
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -167,7 +168,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::indices-exists-async
|
||||
client.indices().existsAsync(request, listener); // <1>
|
||||
client.indices().existsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::indices-exists-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -177,7 +178,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -199,7 +200,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::delete-index-request-indicesOptions
|
||||
|
||||
// tag::delete-index-execute
|
||||
DeleteIndexResponse deleteIndexResponse = client.indices().delete(request);
|
||||
DeleteIndexResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);
|
||||
// end::delete-index-execute
|
||||
|
||||
// tag::delete-index-response
|
||||
|
@ -212,7 +213,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::delete-index-notfound
|
||||
try {
|
||||
DeleteIndexRequest request = new DeleteIndexRequest("does_not_exist");
|
||||
client.indices().delete(request);
|
||||
client.indices().delete(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -226,7 +227,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
final RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -253,7 +254,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::delete-index-execute-async
|
||||
client.indices().deleteAsync(request, listener); // <1>
|
||||
client.indices().deleteAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::delete-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -289,7 +290,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
"}", // <2>
|
||||
XContentType.JSON);
|
||||
// end::create-index-request-mappings
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -306,7 +307,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
jsonMap.put("tweet", tweet);
|
||||
request.mapping("tweet", jsonMap); // <1>
|
||||
//end::create-index-mappings-map
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
{
|
||||
|
@ -332,7 +333,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
builder.endObject();
|
||||
request.mapping("tweet", builder); // <1>
|
||||
//end::create-index-mappings-xcontent
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
{
|
||||
|
@ -340,7 +341,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
//tag::create-index-mappings-shortcut
|
||||
request.mapping("tweet", "message", "type=text"); // <1>
|
||||
//end::create-index-mappings-shortcut
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -362,7 +363,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
request.waitForActiveShards(ActiveShardCount.DEFAULT); // <2>
|
||||
// end::create-index-request-waitForActiveShards
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -387,7 +388,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::create-index-whole-source
|
||||
|
||||
// tag::create-index-execute
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request);
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
// end::create-index-execute
|
||||
|
||||
// tag::create-index-response
|
||||
|
@ -426,7 +427,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::create-index-execute-async
|
||||
client.indices().createAsync(request, listener); // <1>
|
||||
client.indices().createAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::create-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -437,7 +438,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -459,7 +460,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
"}", // <1>
|
||||
XContentType.JSON);
|
||||
// end::put-mapping-request-source
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
assertTrue(putMappingResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -473,7 +474,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
jsonMap.put("properties", properties);
|
||||
request.source(jsonMap); // <1>
|
||||
//end::put-mapping-map
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
assertTrue(putMappingResponse.isAcknowledged());
|
||||
}
|
||||
{
|
||||
|
@ -494,14 +495,14 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
builder.endObject();
|
||||
request.source(builder); // <1>
|
||||
//end::put-mapping-xcontent
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
assertTrue(putMappingResponse.isAcknowledged());
|
||||
}
|
||||
{
|
||||
//tag::put-mapping-shortcut
|
||||
request.source("message", "type=text"); // <1>
|
||||
//end::put-mapping-shortcut
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
assertTrue(putMappingResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -515,7 +516,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::put-mapping-request-masterTimeout
|
||||
|
||||
// tag::put-mapping-execute
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
|
||||
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
// end::put-mapping-execute
|
||||
|
||||
// tag::put-mapping-response
|
||||
|
@ -529,7 +530,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
final RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -556,7 +557,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::put-mapping-execute-async
|
||||
client.indices().putMappingAsync(request, listener); // <1>
|
||||
client.indices().putMappingAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::put-mapping-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -601,7 +602,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::get-mapping-request-indicesOptions
|
||||
|
||||
// tag::get-mapping-execute
|
||||
GetMappingsResponse getMappingResponse = client.indices().getMappings(request);
|
||||
GetMappingsResponse getMappingResponse = client.indices().getMappings(request, RequestOptions.DEFAULT);
|
||||
// end::get-mapping-execute
|
||||
|
||||
// tag::get-mapping-response
|
||||
|
@ -683,7 +684,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
});
|
||||
|
||||
// tag::get-mapping-execute-async
|
||||
client.indices().getMappingsAsync(request, listener); // <1>
|
||||
client.indices().getMappingsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::get-mapping-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -694,7 +695,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -721,7 +722,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::open-index-request-indicesOptions
|
||||
|
||||
// tag::open-index-execute
|
||||
OpenIndexResponse openIndexResponse = client.indices().open(request);
|
||||
OpenIndexResponse openIndexResponse = client.indices().open(request, RequestOptions.DEFAULT);
|
||||
// end::open-index-execute
|
||||
|
||||
// tag::open-index-response
|
||||
|
@ -751,7 +752,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::open-index-execute-async
|
||||
client.indices().openAsync(request, listener); // <1>
|
||||
client.indices().openAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::open-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -761,7 +762,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::open-index-notfound
|
||||
try {
|
||||
OpenIndexRequest request = new OpenIndexRequest("does_not_exist");
|
||||
client.indices().open(request);
|
||||
client.indices().open(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.BAD_REQUEST) {
|
||||
// <1>
|
||||
|
@ -790,7 +791,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::refresh-request-indicesOptions
|
||||
|
||||
// tag::refresh-execute
|
||||
RefreshResponse refreshResponse = client.indices().refresh(request);
|
||||
RefreshResponse refreshResponse = client.indices().refresh(request, RequestOptions.DEFAULT);
|
||||
// end::refresh-execute
|
||||
|
||||
// tag::refresh-response
|
||||
|
@ -819,7 +820,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::refresh-execute-async
|
||||
client.indices().refreshAsync(request, listener); // <1>
|
||||
client.indices().refreshAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::refresh-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -829,7 +830,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::refresh-notfound
|
||||
try {
|
||||
RefreshRequest request = new RefreshRequest("does_not_exist");
|
||||
client.indices().refresh(request);
|
||||
client.indices().refresh(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -866,7 +867,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::flush-request-force
|
||||
|
||||
// tag::flush-execute
|
||||
FlushResponse flushResponse = client.indices().flush(request);
|
||||
FlushResponse flushResponse = client.indices().flush(request, RequestOptions.DEFAULT);
|
||||
// end::flush-execute
|
||||
|
||||
// tag::flush-response
|
||||
|
@ -895,7 +896,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::flush-execute-async
|
||||
client.indices().flushAsync(request, listener); // <1>
|
||||
client.indices().flushAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::flush-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -905,7 +906,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::flush-notfound
|
||||
try {
|
||||
FlushRequest request = new FlushRequest("does_not_exist");
|
||||
client.indices().flush(request);
|
||||
client.indices().flush(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -934,7 +935,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::flush-synced-request-indicesOptions
|
||||
|
||||
// tag::flush-synced-execute
|
||||
SyncedFlushResponse flushSyncedResponse = client.indices().flushSynced(request);
|
||||
SyncedFlushResponse flushSyncedResponse = client.indices().flushSynced(request, RequestOptions.DEFAULT);
|
||||
// end::flush-synced-execute
|
||||
|
||||
// tag::flush-synced-response
|
||||
|
@ -978,7 +979,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::flush-synced-execute-async
|
||||
client.indices().flushSyncedAsync(request, listener); // <1>
|
||||
client.indices().flushSyncedAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::flush-synced-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -988,7 +989,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::flush-synced-notfound
|
||||
try {
|
||||
SyncedFlushRequest request = new SyncedFlushRequest("does_not_exist");
|
||||
client.indices().flushSynced(request);
|
||||
client.indices().flushSynced(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -1003,7 +1004,8 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
|
||||
{
|
||||
Settings settings = Settings.builder().put("number_of_shards", 3).build();
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index", settings));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(
|
||||
new CreateIndexRequest("index", settings), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1020,7 +1022,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::get-settings-request-indicesOptions
|
||||
|
||||
// tag::get-settings-execute
|
||||
GetSettingsResponse getSettingsResponse = client.indices().getSettings(request);
|
||||
GetSettingsResponse getSettingsResponse = client.indices().getSettings(request, RequestOptions.DEFAULT);
|
||||
// end::get-settings-execute
|
||||
|
||||
// tag::get-settings-response
|
||||
|
@ -1055,7 +1057,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::get-settings-execute-async
|
||||
client.indices().getSettingsAsync(request, listener); // <1>
|
||||
client.indices().getSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::get-settings-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1066,7 +1068,8 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
|
||||
{
|
||||
Settings settings = Settings.builder().put("number_of_shards", 3).build();
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index", settings));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(
|
||||
new CreateIndexRequest("index", settings), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1077,7 +1080,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
request.includeDefaults(true); // <1>
|
||||
// end::get-settings-request-include-defaults
|
||||
|
||||
GetSettingsResponse getSettingsResponse = client.indices().getSettings(request);
|
||||
GetSettingsResponse getSettingsResponse = client.indices().getSettings(request, RequestOptions.DEFAULT);
|
||||
String numberOfShardsString = getSettingsResponse.getSetting("index", "index.number_of_shards");
|
||||
Settings indexSettings = getSettingsResponse.getIndexToSettings().get("index");
|
||||
Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null);
|
||||
|
@ -1107,7 +1110,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
client.indices().getSettingsAsync(request, listener);
|
||||
client.indices().getSettingsAsync(request, RequestOptions.DEFAULT, listener);
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
|
@ -1142,7 +1145,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::force-merge-request-flush
|
||||
|
||||
// tag::force-merge-execute
|
||||
ForceMergeResponse forceMergeResponse = client.indices().forceMerge(request);
|
||||
ForceMergeResponse forceMergeResponse = client.indices().forceMerge(request, RequestOptions.DEFAULT);
|
||||
// end::force-merge-execute
|
||||
|
||||
// tag::force-merge-response
|
||||
|
@ -1167,14 +1170,14 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::force-merge-execute-listener
|
||||
|
||||
// tag::force-merge-execute-async
|
||||
client.indices().forceMergeAsync(request, listener); // <1>
|
||||
client.indices().forceMergeAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::force-merge-execute-async
|
||||
}
|
||||
{
|
||||
// tag::force-merge-notfound
|
||||
try {
|
||||
ForceMergeRequest request = new ForceMergeRequest("does_not_exist");
|
||||
client.indices().forceMerge(request);
|
||||
client.indices().forceMerge(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -1219,7 +1222,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::clear-cache-request-fields
|
||||
|
||||
// tag::clear-cache-execute
|
||||
ClearIndicesCacheResponse clearCacheResponse = client.indices().clearCache(request);
|
||||
ClearIndicesCacheResponse clearCacheResponse = client.indices().clearCache(request, RequestOptions.DEFAULT);
|
||||
// end::clear-cache-execute
|
||||
|
||||
// tag::clear-cache-response
|
||||
|
@ -1248,7 +1251,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::clear-cache-execute-async
|
||||
client.indices().clearCacheAsync(request, listener); // <1>
|
||||
client.indices().clearCacheAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::clear-cache-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1258,7 +1261,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// tag::clear-cache-notfound
|
||||
try {
|
||||
ClearIndicesCacheRequest request = new ClearIndicesCacheRequest("does_not_exist");
|
||||
client.indices().clearCache(request);
|
||||
client.indices().clearCache(request, RequestOptions.DEFAULT);
|
||||
} catch (ElasticsearchException exception) {
|
||||
if (exception.status() == RestStatus.NOT_FOUND) {
|
||||
// <1>
|
||||
|
@ -1272,7 +1275,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1295,7 +1298,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::close-index-request-indicesOptions
|
||||
|
||||
// tag::close-index-execute
|
||||
CloseIndexResponse closeIndexResponse = client.indices().close(request);
|
||||
CloseIndexResponse closeIndexResponse = client.indices().close(request, RequestOptions.DEFAULT);
|
||||
// end::close-index-execute
|
||||
|
||||
// tag::close-index-response
|
||||
|
@ -1323,7 +1326,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::close-index-execute-async
|
||||
client.indices().closeAsync(request, listener); // <1>
|
||||
client.indices().closeAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::close-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1335,7 +1338,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index")
|
||||
.alias(new Alias("alias")));
|
||||
.alias(new Alias("alias")), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1363,7 +1366,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::exists-alias-request-local
|
||||
|
||||
// tag::exists-alias-execute
|
||||
boolean exists = client.indices().existsAlias(request);
|
||||
boolean exists = client.indices().existsAlias(request, RequestOptions.DEFAULT);
|
||||
// end::exists-alias-execute
|
||||
assertTrue(exists);
|
||||
|
||||
|
@ -1386,7 +1389,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::exists-alias-execute-async
|
||||
client.indices().existsAliasAsync(request, listener); // <1>
|
||||
client.indices().existsAliasAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::exists-alias-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1397,13 +1400,13 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index1"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index1"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index2"));
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index2"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index3"));
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index3"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index4"));
|
||||
createIndexResponse = client.indices().create(new CreateIndexRequest("index4"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1448,7 +1451,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
|
||||
// tag::update-aliases-execute
|
||||
IndicesAliasesResponse indicesAliasesResponse =
|
||||
client.indices().updateAliases(request);
|
||||
client.indices().updateAliases(request, RequestOptions.DEFAULT);
|
||||
// end::update-aliases-execute
|
||||
|
||||
// tag::update-aliases-response
|
||||
|
@ -1482,7 +1485,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::update-aliases-execute-async
|
||||
client.indices().updateAliasesAsync(request, listener); // <1>
|
||||
client.indices().updateAliasesAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::update-aliases-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1527,7 +1530,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::shrink-index-request-aliases
|
||||
|
||||
// tag::shrink-index-execute
|
||||
ResizeResponse resizeResponse = client.indices().shrink(request);
|
||||
ResizeResponse resizeResponse = client.indices().shrink(request, RequestOptions.DEFAULT);
|
||||
// end::shrink-index-execute
|
||||
|
||||
// tag::shrink-index-response
|
||||
|
@ -1556,7 +1559,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::shrink-index-execute-async
|
||||
client.indices().shrinkAsync(request, listener); // <1>
|
||||
client.indices().shrinkAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::shrink-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1597,7 +1600,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::split-index-request-aliases
|
||||
|
||||
// tag::split-index-execute
|
||||
ResizeResponse resizeResponse = client.indices().split(request);
|
||||
ResizeResponse resizeResponse = client.indices().split(request, RequestOptions.DEFAULT);
|
||||
// end::split-index-execute
|
||||
|
||||
// tag::split-index-response
|
||||
|
@ -1626,7 +1629,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::split-index-execute-async
|
||||
client.indices().splitAsync(request,listener); // <1>
|
||||
client.indices().splitAsync(request, RequestOptions.DEFAULT,listener); // <1>
|
||||
// end::split-index-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1636,7 +1639,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
client.indices().create(new CreateIndexRequest("index-1").alias(new Alias("alias")));
|
||||
client.indices().create(new CreateIndexRequest("index-1").alias(new Alias("alias")), RequestOptions.DEFAULT);
|
||||
}
|
||||
|
||||
// tag::rollover-request
|
||||
|
@ -1673,7 +1676,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::rollover-request-alias
|
||||
|
||||
// tag::rollover-execute
|
||||
RolloverResponse rolloverResponse = client.indices().rollover(request);
|
||||
RolloverResponse rolloverResponse = client.indices().rollover(request, RequestOptions.DEFAULT);
|
||||
// end::rollover-execute
|
||||
|
||||
// tag::rollover-response
|
||||
|
@ -1712,7 +1715,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::rollover-execute-async
|
||||
client.indices().rolloverAsync(request,listener); // <1>
|
||||
client.indices().rolloverAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::rollover-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1722,7 +1725,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"));
|
||||
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
|
@ -1785,7 +1788,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
|
||||
// tag::put-settings-execute
|
||||
UpdateSettingsResponse updateSettingsResponse =
|
||||
client.indices().putSettings(request);
|
||||
client.indices().putSettings(request, RequestOptions.DEFAULT);
|
||||
// end::put-settings-execute
|
||||
|
||||
// tag::put-settings-response
|
||||
|
@ -1814,7 +1817,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::put-settings-execute-async
|
||||
client.indices().putSettingsAsync(request,listener); // <1>
|
||||
client.indices().putSettingsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::put-settings-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1849,7 +1852,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
"}", // <2>
|
||||
XContentType.JSON);
|
||||
// end::put-template-request-mappings-json
|
||||
assertTrue(client.indices().putTemplate(request).isAcknowledged());
|
||||
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
|
||||
}
|
||||
{
|
||||
//tag::put-template-request-mappings-map
|
||||
|
@ -1863,7 +1866,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
jsonMap.put("tweet", tweet);
|
||||
request.mapping("tweet", jsonMap); // <1>
|
||||
//end::put-template-request-mappings-map
|
||||
assertTrue(client.indices().putTemplate(request).isAcknowledged());
|
||||
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
|
||||
}
|
||||
{
|
||||
//tag::put-template-request-mappings-xcontent
|
||||
|
@ -1887,13 +1890,13 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
builder.endObject();
|
||||
request.mapping("tweet", builder); // <1>
|
||||
//end::put-template-request-mappings-xcontent
|
||||
assertTrue(client.indices().putTemplate(request).isAcknowledged());
|
||||
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
|
||||
}
|
||||
{
|
||||
//tag::put-template-request-mappings-shortcut
|
||||
request.mapping("tweet", "message", "type=text"); // <1>
|
||||
//end::put-template-request-mappings-shortcut
|
||||
assertTrue(client.indices().putTemplate(request).isAcknowledged());
|
||||
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
|
||||
}
|
||||
|
||||
// tag::put-template-request-aliases
|
||||
|
@ -1947,7 +1950,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
request.create(false); // make test happy
|
||||
|
||||
// tag::put-template-execute
|
||||
PutIndexTemplateResponse putTemplateResponse = client.indices().putTemplate(request);
|
||||
PutIndexTemplateResponse putTemplateResponse = client.indices().putTemplate(request, RequestOptions.DEFAULT);
|
||||
// end::put-template-execute
|
||||
|
||||
// tag::put-template-response
|
||||
|
@ -1975,7 +1978,7 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::put-template-execute-async
|
||||
client.indices().putTemplateAsync(request, listener); // <1>
|
||||
client.indices().putTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::put-template-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.action.ingest.GetPipelineResponse;
|
|||
import org.elasticsearch.action.ingest.PutPipelineRequest;
|
||||
import org.elasticsearch.action.ingest.WritePipelineResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
@ -86,7 +87,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::put-pipeline-request-masterTimeout
|
||||
|
||||
// tag::put-pipeline-execute
|
||||
WritePipelineResponse response = client.ingest().putPipeline(request); // <1>
|
||||
WritePipelineResponse response = client.ingest().putPipeline(request, RequestOptions.DEFAULT); // <1>
|
||||
// end::put-pipeline-execute
|
||||
|
||||
// tag::put-pipeline-response
|
||||
|
@ -129,7 +130,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::put-pipeline-execute-async
|
||||
client.ingest().putPipelineAsync(request, listener); // <1>
|
||||
client.ingest().putPipelineAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::put-pipeline-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -154,7 +155,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::get-pipeline-request-masterTimeout
|
||||
|
||||
// tag::get-pipeline-execute
|
||||
GetPipelineResponse response = client.ingest().getPipeline(request); // <1>
|
||||
GetPipelineResponse response = client.ingest().getPipeline(request, RequestOptions.DEFAULT); // <1>
|
||||
// end::get-pipeline-execute
|
||||
|
||||
// tag::get-pipeline-response
|
||||
|
@ -199,7 +200,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::get-pipeline-execute-async
|
||||
client.ingest().getPipelineAsync(request, listener); // <1>
|
||||
client.ingest().getPipelineAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::get-pipeline-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -229,7 +230,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::delete-pipeline-request-masterTimeout
|
||||
|
||||
// tag::delete-pipeline-execute
|
||||
WritePipelineResponse response = client.ingest().deletePipeline(request); // <1>
|
||||
WritePipelineResponse response = client.ingest().deletePipeline(request, RequestOptions.DEFAULT); // <1>
|
||||
// end::delete-pipeline-execute
|
||||
|
||||
// tag::delete-pipeline-response
|
||||
|
@ -269,7 +270,7 @@ public class IngestClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::delete-pipeline-execute-async
|
||||
client.ingest().deletePipelineAsync(request, listener); // <1>
|
||||
client.ingest().deletePipelineAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::delete-pipeline-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
|
||||
package org.elasticsearch.client.documentation;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
|
@ -31,12 +27,10 @@ import org.elasticsearch.action.index.IndexRequest;
|
|||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -45,11 +39,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
|
||||
/**
|
||||
* This class is used to generate the documentation for the
|
||||
* docs/java-rest/high-level/migration.asciidoc page.
|
||||
|
@ -98,14 +87,14 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
//end::migration-request-ctor
|
||||
|
||||
//tag::migration-request-ctor-execution
|
||||
IndexResponse response = client.index(request);
|
||||
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
|
||||
//end::migration-request-ctor-execution
|
||||
assertEquals(RestStatus.CREATED, response.status());
|
||||
}
|
||||
{
|
||||
//tag::migration-request-async-execution
|
||||
DeleteRequest request = new DeleteRequest("index", "doc", "id"); // <1>
|
||||
client.deleteAsync(request, new ActionListener<DeleteResponse>() { // <2>
|
||||
client.deleteAsync(request, RequestOptions.DEFAULT, new ActionListener<DeleteResponse>() { // <2>
|
||||
@Override
|
||||
public void onResponse(DeleteResponse deleteResponse) {
|
||||
// <3>
|
||||
|
@ -117,12 +106,12 @@ public class MigrationDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
});
|
||||
//end::migration-request-async-execution
|
||||
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "doc", "id"))));
|
||||
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "doc", "id"), RequestOptions.DEFAULT)));
|
||||
}
|
||||
{
|
||||
//tag::migration-request-sync-execution
|
||||
DeleteRequest request = new DeleteRequest("index", "doc", "id");
|
||||
DeleteResponse response = client.delete(request); // <1>
|
||||
DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); // <1>
|
||||
//end::migration-request-sync-execution
|
||||
assertEquals(RestStatus.NOT_FOUND, response.status());
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.Build;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.main.MainResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
|
@ -40,7 +41,7 @@ public class MiscellaneousDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
{
|
||||
//tag::main-execute
|
||||
MainResponse response = client.info();
|
||||
MainResponse response = client.info(RequestOptions.DEFAULT);
|
||||
//end::main-execute
|
||||
//tag::main-response
|
||||
ClusterName clusterName = response.getClusterName(); // <1>
|
||||
|
@ -60,7 +61,7 @@ public class MiscellaneousDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
public void testPing() throws IOException {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
//tag::ping-execute
|
||||
boolean response = client.ping();
|
||||
boolean response = client.ping(RequestOptions.DEFAULT);
|
||||
//end::ping-execute
|
||||
assertTrue(response);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.elasticsearch.action.support.IndicesOptions;
|
|||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
@ -143,7 +144,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// tag::search-request-preference
|
||||
searchRequest.preference("_local"); // <1>
|
||||
// end::search-request-preference
|
||||
assertNotNull(client.search(searchRequest));
|
||||
assertNotNull(client.search(searchRequest, RequestOptions.DEFAULT));
|
||||
}
|
||||
{
|
||||
// tag::search-source-basics
|
||||
|
@ -176,7 +177,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::search-source-setter
|
||||
|
||||
// tag::search-execute
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
// end::search-execute
|
||||
|
||||
// tag::search-execute-listener
|
||||
|
@ -198,7 +199,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::search-execute-async
|
||||
client.searchAsync(searchRequest, listener); // <1>
|
||||
client.searchAsync(searchRequest, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::search-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -296,7 +297,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new IndexRequest("posts", "doc", "3")
|
||||
.source(XContentType.JSON, "company", "Elastic", "age", 40));
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.OK, bulkResponse.status());
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
}
|
||||
|
@ -312,7 +313,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::search-request-aggregations
|
||||
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
{
|
||||
// tag::search-request-aggregations-get
|
||||
Aggregations aggregations = searchResponse.getAggregations();
|
||||
|
@ -369,7 +370,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new IndexRequest("posts", "doc", "3").source(XContentType.JSON, "user", "tlrx"));
|
||||
request.add(new IndexRequest("posts", "doc", "4").source(XContentType.JSON, "user", "cbuescher"));
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.OK, bulkResponse.status());
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
}
|
||||
|
@ -384,7 +385,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.suggest(suggestBuilder);
|
||||
// end::search-request-suggestion
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
{
|
||||
// tag::search-request-suggestion-get
|
||||
Suggest suggest = searchResponse.getSuggest(); // <1>
|
||||
|
@ -416,7 +417,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch", "user",
|
||||
Arrays.asList("kimchy", "tanguy"), "innerObject", Collections.singletonMap("key", "value")));
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.OK, bulkResponse.status());
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
}
|
||||
|
@ -437,7 +438,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
.should(matchQuery("title", "Elasticsearch"))
|
||||
.should(matchQuery("user", "kimchy")));
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
{
|
||||
// tag::search-request-highlighting-get
|
||||
SearchHits hits = searchResponse.getHits();
|
||||
|
@ -472,7 +473,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
IndexRequest request = new IndexRequest("posts", "doc", "1")
|
||||
.source(XContentType.JSON, "tags", "elasticsearch", "comments", 123);
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
|
||||
IndexResponse indexResponse = client.index(request);
|
||||
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.CREATED, indexResponse.status());
|
||||
}
|
||||
{
|
||||
|
@ -485,7 +486,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.aggregation(AggregationBuilders.histogram("by_comments").field("comments").interval(100));
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
// tag::search-request-profiling-get
|
||||
Map<String, ProfileShardResult> profilingResults =
|
||||
searchResponse.getProfileResults(); // <1>
|
||||
|
@ -548,7 +549,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new IndexRequest("posts", "doc", "3")
|
||||
.source(XContentType.JSON, "title", "The Future of Federated Search in Elasticsearch"));
|
||||
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = client.bulk(request);
|
||||
BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.OK, bulkResponse.status());
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
}
|
||||
|
@ -561,7 +562,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.size(size); // <1>
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
searchRequest.scroll(TimeValue.timeValueMinutes(1L)); // <2>
|
||||
SearchResponse searchResponse = client.search(searchRequest);
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
String scrollId = searchResponse.getScrollId(); // <3>
|
||||
SearchHits hits = searchResponse.getHits(); // <4>
|
||||
// end::search-scroll-init
|
||||
|
@ -572,7 +573,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// tag::search-scroll2
|
||||
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <1>
|
||||
scrollRequest.scroll(TimeValue.timeValueSeconds(30));
|
||||
SearchResponse searchScrollResponse = client.searchScroll(scrollRequest);
|
||||
SearchResponse searchScrollResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
|
||||
scrollId = searchScrollResponse.getScrollId(); // <2>
|
||||
hits = searchScrollResponse.getHits(); // <3>
|
||||
assertEquals(3, hits.getTotalHits());
|
||||
|
@ -582,14 +583,14 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
|
||||
clearScrollRequest.addScrollId(scrollId);
|
||||
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest);
|
||||
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(clearScrollResponse.isSucceeded());
|
||||
}
|
||||
{
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.scroll("60s");
|
||||
|
||||
SearchResponse initialSearchResponse = client.search(searchRequest);
|
||||
SearchResponse initialSearchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
String scrollId = initialSearchResponse.getScrollId();
|
||||
|
||||
SearchScrollRequest scrollRequest = new SearchScrollRequest();
|
||||
|
@ -601,7 +602,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::scroll-request-arguments
|
||||
|
||||
// tag::search-scroll-execute-sync
|
||||
SearchResponse searchResponse = client.searchScroll(scrollRequest);
|
||||
SearchResponse searchResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
|
||||
// end::search-scroll-execute-sync
|
||||
|
||||
assertEquals(0, searchResponse.getFailedShards());
|
||||
|
@ -648,7 +649,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::clear-scroll-add-scroll-ids
|
||||
|
||||
// tag::clear-scroll-execute
|
||||
ClearScrollResponse response = client.clearScroll(request);
|
||||
ClearScrollResponse response = client.clearScroll(request, RequestOptions.DEFAULT);
|
||||
// end::clear-scroll-execute
|
||||
|
||||
// tag::clear-scroll-response
|
||||
|
@ -678,7 +679,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, clearScrollLatch);
|
||||
|
||||
// tag::clear-scroll-execute-async
|
||||
client.clearScrollAsync(request, listener); // <1>
|
||||
client.clearScrollAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::clear-scroll-execute-async
|
||||
|
||||
assertTrue(clearScrollLatch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -692,14 +693,14 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
searchSourceBuilder.query(matchQuery("title", "Elasticsearch"));
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = client.search(searchRequest); // <1>
|
||||
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); // <1>
|
||||
String scrollId = searchResponse.getScrollId();
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
while (searchHits != null && searchHits.length > 0) { // <2>
|
||||
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); // <3>
|
||||
scrollRequest.scroll(scroll);
|
||||
searchResponse = client.searchScroll(scrollRequest);
|
||||
searchResponse = client.searchScroll(scrollRequest, RequestOptions.DEFAULT);
|
||||
scrollId = searchResponse.getScrollId();
|
||||
searchHits = searchResponse.getHits().getHits();
|
||||
// <4>
|
||||
|
@ -707,7 +708,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); // <5>
|
||||
clearScrollRequest.addScrollId(scrollId);
|
||||
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest);
|
||||
ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT);
|
||||
boolean succeeded = clearScrollResponse.isSucceeded();
|
||||
// end::search-scroll-example
|
||||
assertTrue(succeeded);
|
||||
|
@ -737,7 +738,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::search-template-request-inline
|
||||
|
||||
// tag::search-template-response
|
||||
SearchTemplateResponse response = client.searchTemplate(request);
|
||||
SearchTemplateResponse response = client.searchTemplate(request, RequestOptions.DEFAULT);
|
||||
SearchResponse searchResponse = response.getResponse();
|
||||
// end::search-template-response
|
||||
|
||||
|
@ -749,7 +750,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::render-search-template-request
|
||||
|
||||
// tag::render-search-template-response
|
||||
SearchTemplateResponse renderResponse = client.searchTemplate(request);
|
||||
SearchTemplateResponse renderResponse = client.searchTemplate(request, RequestOptions.DEFAULT);
|
||||
BytesReference source = renderResponse.getSource(); // <1>
|
||||
// end::render-search-template-response
|
||||
|
||||
|
@ -802,7 +803,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::search-template-request-options
|
||||
|
||||
// tag::search-template-execute
|
||||
SearchTemplateResponse response = client.searchTemplate(request);
|
||||
SearchTemplateResponse response = client.searchTemplate(request, RequestOptions.DEFAULT);
|
||||
// end::search-template-execute
|
||||
|
||||
SearchResponse searchResponse = response.getResponse();
|
||||
|
@ -828,7 +829,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::search-template-execute-async
|
||||
client.searchTemplateAsync(request, listener); // <1>
|
||||
client.searchTemplateAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::search-template-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -849,7 +850,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::field-caps-request-indicesOptions
|
||||
|
||||
// tag::field-caps-execute
|
||||
FieldCapabilitiesResponse response = client.fieldCaps(request);
|
||||
FieldCapabilitiesResponse response = client.fieldCaps(request, RequestOptions.DEFAULT);
|
||||
// end::field-caps-execute
|
||||
|
||||
// tag::field-caps-response
|
||||
|
@ -892,7 +893,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::field-caps-execute-async
|
||||
client.fieldCapsAsync(request, listener); // <1>
|
||||
client.fieldCapsAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::field-caps-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -918,7 +919,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
// end::rank-eval-request-basic
|
||||
|
||||
// tag::rank-eval-execute
|
||||
RankEvalResponse response = client.rankEval(request);
|
||||
RankEvalResponse response = client.rankEval(request, RequestOptions.DEFAULT);
|
||||
// end::rank-eval-execute
|
||||
|
||||
// tag::rank-eval-response
|
||||
|
@ -962,7 +963,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::rank-eval-execute-async
|
||||
client.rankEvalAsync(request, listener); // <1>
|
||||
client.rankEvalAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::rank-eval-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -987,7 +988,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(secondSearchRequest);
|
||||
// end::multi-search-request-basic
|
||||
// tag::multi-search-execute
|
||||
MultiSearchResponse response = client.multiSearch(request);
|
||||
MultiSearchResponse response = client.multiSearch(request, RequestOptions.DEFAULT);
|
||||
// end::multi-search-execute
|
||||
// tag::multi-search-response
|
||||
MultiSearchResponse.Item firstResponse = response.getResponses()[0]; // <1>
|
||||
|
@ -1019,7 +1020,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::multi-search-execute-async
|
||||
client.multiSearchAsync(request, listener); // <1>
|
||||
client.multiSearchAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::multi-search-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -1030,7 +1031,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
request.add(new SearchRequest("posts") // <1>
|
||||
.types("doc")); // <2>
|
||||
// end::multi-search-request-index
|
||||
MultiSearchResponse response = client.multiSearch(request);
|
||||
MultiSearchResponse response = client.multiSearch(request, RequestOptions.DEFAULT);
|
||||
MultiSearchResponse.Item firstResponse = response.getResponses()[0];
|
||||
assertNull(firstResponse.getFailure());
|
||||
SearchResponse searchResponse = firstResponse.getResponse();
|
||||
|
@ -1041,12 +1042,12 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
private void indexSearchTestData() throws IOException {
|
||||
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors")
|
||||
.mapping("doc", "user", "type=keyword,doc_values=false");
|
||||
CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest);
|
||||
CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(authorsResponse.isAcknowledged());
|
||||
|
||||
CreateIndexRequest reviewersRequest = new CreateIndexRequest("contributors")
|
||||
.mapping("doc", "user", "type=keyword");
|
||||
CreateIndexResponse reviewersResponse = highLevelClient().indices().create(reviewersRequest);
|
||||
CreateIndexResponse reviewersResponse = highLevelClient().indices().create(reviewersRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(reviewersResponse.isAcknowledged());
|
||||
|
||||
BulkRequest bulkRequest = new BulkRequest();
|
||||
|
@ -1067,7 +1068,7 @@ public class SearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
|
||||
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest);
|
||||
BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT);
|
||||
assertSame(RestStatus.OK, bulkResponse.status());
|
||||
assertFalse(bulkResponse.hasFailures());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResp
|
|||
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -134,7 +135,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::create-repository-request-verify
|
||||
|
||||
// tag::create-repository-execute
|
||||
PutRepositoryResponse response = client.snapshot().createRepository(request);
|
||||
PutRepositoryResponse response = client.snapshot().createRepository(request, RequestOptions.DEFAULT);
|
||||
// end::create-repository-execute
|
||||
|
||||
// tag::create-repository-response
|
||||
|
@ -168,7 +169,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::create-repository-execute-async
|
||||
client.snapshot().createRepositoryAsync(request, listener); // <1>
|
||||
client.snapshot().createRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::create-repository-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -197,7 +198,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::get-repository-request-masterTimeout
|
||||
|
||||
// tag::get-repository-execute
|
||||
GetRepositoriesResponse response = client.snapshot().getRepositories(request);
|
||||
GetRepositoriesResponse response = client.snapshot().getRepositories(request, RequestOptions.DEFAULT);
|
||||
// end::get-repository-execute
|
||||
|
||||
// tag::get-repository-response
|
||||
|
@ -232,7 +233,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::get-repository-execute-async
|
||||
client.snapshot().getRepositoriesAsync(request, listener); // <1>
|
||||
client.snapshot().getRepositoriesAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::get-repository-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -258,7 +259,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::delete-repository-request-timeout
|
||||
|
||||
// tag::delete-repository-execute
|
||||
DeleteRepositoryResponse response = client.snapshot().deleteRepository(request);
|
||||
DeleteRepositoryResponse response = client.snapshot().deleteRepository(request, RequestOptions.DEFAULT);
|
||||
// end::delete-repository-execute
|
||||
|
||||
// tag::delete-repository-response
|
||||
|
@ -292,7 +293,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::delete-repository-execute-async
|
||||
client.snapshot().deleteRepositoryAsync(request, listener); // <1>
|
||||
client.snapshot().deleteRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::delete-repository-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -317,7 +318,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
// end::verify-repository-request-timeout
|
||||
|
||||
// tag::verify-repository-execute
|
||||
VerifyRepositoryResponse response = client.snapshot().verifyRepository(request);
|
||||
VerifyRepositoryResponse response = client.snapshot().verifyRepository(request, RequestOptions.DEFAULT);
|
||||
// end::verify-repository-execute
|
||||
|
||||
// tag::verify-repository-response
|
||||
|
@ -352,7 +353,7 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::verify-repository-execute-async
|
||||
client.snapshot().verifyRepositoryAsync(request, listener); // <1>
|
||||
client.snapshot().verifyRepositoryAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::verify-repository-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
@ -363,6 +364,6 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|||
PutRepositoryRequest request = new PutRepositoryRequest(repositoryName);
|
||||
request.type(FsRepository.TYPE);
|
||||
request.settings("{\"location\": \".\"}", XContentType.JSON);
|
||||
assertTrue(highLevelClient().snapshot().createRepository(request).isAcknowledged());
|
||||
assertTrue(highLevelClient().snapshot().createRepository(request, RequestOptions.DEFAULT).isAcknowledged());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,13 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.LatchedActionListener;
|
||||
import org.elasticsearch.action.TaskOperationFailure;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
||||
import org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.tasks.TaskId;
|
||||
|
@ -90,7 +93,7 @@ public class TasksClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
ListTasksRequest request = new ListTasksRequest();
|
||||
|
||||
// tag::list-tasks-execute
|
||||
ListTasksResponse response = client.tasks().list(request);
|
||||
ListTasksResponse response = client.tasks().list(request, RequestOptions.DEFAULT);
|
||||
// end::list-tasks-execute
|
||||
|
||||
assertThat(response, notNullValue());
|
||||
|
@ -139,10 +142,80 @@ public class TasksClientDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::list-tasks-execute-async
|
||||
client.tasks().listAsync(request, listener); // <1>
|
||||
client.tasks().listAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::list-tasks-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
public void testCancelTasks() throws IOException {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
{
|
||||
// tag::cancel-tasks-request
|
||||
CancelTasksRequest request = new CancelTasksRequest();
|
||||
// end::cancel-tasks-request
|
||||
|
||||
// tag::cancel-tasks-request-filter
|
||||
request.setTaskId(new TaskId("nodeId1", 42)); //<1>
|
||||
request.setActions("cluster:*"); // <2>
|
||||
request.setNodes("nodeId1", "nodeId2"); // <3>
|
||||
// end::cancel-tasks-request-filter
|
||||
|
||||
}
|
||||
|
||||
CancelTasksRequest request = new CancelTasksRequest();
|
||||
request.setTaskId(TaskId.EMPTY_TASK_ID);
|
||||
|
||||
// tag::cancel-tasks-execute
|
||||
CancelTasksResponse response = client.tasks().cancel(request, RequestOptions.DEFAULT);
|
||||
// end::cancel-tasks-execute
|
||||
|
||||
assertThat(response, notNullValue());
|
||||
|
||||
// tag::cancel-tasks-response-tasks
|
||||
List<TaskInfo> tasks = response.getTasks(); // <1>
|
||||
// end::cancel-tasks-response-tasks
|
||||
|
||||
|
||||
// tag::cancel-tasks-response-failures
|
||||
List<ElasticsearchException> nodeFailures = response.getNodeFailures(); // <1>
|
||||
List<TaskOperationFailure> taskFailures = response.getTaskFailures(); // <2>
|
||||
// end::-tasks-response-failures
|
||||
|
||||
assertThat(response.getNodeFailures(), equalTo(emptyList()));
|
||||
assertThat(response.getTaskFailures(), equalTo(emptyList()));
|
||||
}
|
||||
|
||||
public void testAsyncCancelTasks() throws InterruptedException {
|
||||
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
{
|
||||
CancelTasksRequest request = new CancelTasksRequest();
|
||||
|
||||
// tag::cancel-tasks-execute-listener
|
||||
ActionListener<CancelTasksResponse> listener =
|
||||
new ActionListener<CancelTasksResponse>() {
|
||||
@Override
|
||||
public void onResponse(CancelTasksResponse response) {
|
||||
// <1>
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::cancel-tasks-execute-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::cancel-tasks-execute-async
|
||||
client.tasks().cancelAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::cancel-tasks-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ forbiddenApisTest {
|
|||
}
|
||||
|
||||
// JarHell is part of es server, which we don't want to pull in
|
||||
// TODO: Not anymore. Now in elasticsearch-core
|
||||
// TODO: Not anymore. Now in :libs:core
|
||||
jarHell.enabled=false
|
||||
|
||||
namingConventions {
|
||||
|
|
|
@ -72,7 +72,7 @@ dependencyLicenses {
|
|||
}
|
||||
|
||||
// JarHell is part of es server, which we don't want to pull in
|
||||
// TODO: Not anymore. Now in elasticsearch-core
|
||||
// TODO: Not anymore. Now in :libs:core
|
||||
jarHell.enabled=false
|
||||
|
||||
namingConventions {
|
||||
|
|
|
@ -30,7 +30,6 @@ import com.sun.net.httpserver.HttpServer;
|
|||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
|
@ -148,8 +147,6 @@ public class ElasticsearchHostsSnifferTests extends RestClientTestCase {
|
|||
return httpServer;
|
||||
}
|
||||
|
||||
//animal-sniffer doesn't like our usage of com.sun.net.httpserver.* classes
|
||||
@IgnoreJRERequirement
|
||||
private static class ResponseHandler implements HttpHandler {
|
||||
private final int sniffTimeoutMillis;
|
||||
private final SniffResponse sniffResponse;
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
|
|||
import org.gradle.api.JavaVersion
|
||||
|
||||
apply plugin: 'elasticsearch.build'
|
||||
apply plugin: 'ru.vyarus.animalsniffer'
|
||||
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
|
@ -31,8 +30,6 @@ dependencies {
|
|||
compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
||||
compile "junit:junit:${versions.junit}"
|
||||
compile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
|
||||
compile "org.codehaus.mojo:animal-sniffer-annotations:1.15"
|
||||
signature "org.codehaus.mojo.signature:java17:1.0@signature"
|
||||
}
|
||||
|
||||
forbiddenApisMain {
|
||||
|
@ -49,7 +46,7 @@ forbiddenApisTest {
|
|||
}
|
||||
|
||||
// JarHell is part of es server, which we don't want to pull in
|
||||
// TODO: Not anymore. Now in elasticsearch-core
|
||||
// TODO: Not anymore. Now in :libs:core
|
||||
jarHell.enabled=false
|
||||
|
||||
// TODO: should we have licenses for our test deps?
|
||||
|
|
|
@ -34,7 +34,7 @@ Collection distributions = project('archives').subprojects + project('packages')
|
|||
task generateDependenciesReport(type: ConcatFilesTask) {
|
||||
files = fileTree(dir: project.rootDir, include: '**/dependencies.csv' )
|
||||
headerLine = "name,version,url,license"
|
||||
target = new File(System.getProperty('csv')?: "${project.buildDir}/dependencies/es-dependencies.csv")
|
||||
target = new File(System.getProperty('csv')?: "${project.buildDir}/reports/dependencies/es-dependencies.csv")
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -231,6 +231,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
|
|||
from { project(':server').jar }
|
||||
from { project(':server').configurations.runtime }
|
||||
from { project(':libs:plugin-classloader').jar }
|
||||
from { project(':distribution:tools:java-version-checker').jar }
|
||||
from { project(':distribution:tools:launchers').jar }
|
||||
into('tools/plugin-cli') {
|
||||
from { project(':distribution:tools:plugin-cli').jar }
|
||||
|
|
|
@ -24,5 +24,5 @@ exec \
|
|||
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
|
||||
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
|
||||
-cp "$ES_CLASSPATH" \
|
||||
$1 \
|
||||
"${@:2}"
|
||||
"$ES_MAIN_CLASS" \
|
||||
"$@"
|
||||
|
|
|
@ -6,11 +6,6 @@ if defined ES_ADDITIONAL_SOURCES (
|
|||
)
|
||||
)
|
||||
|
||||
for /f "tokens=1*" %%a in ("%*") do (
|
||||
set main_class=%%a
|
||||
set arguments=%%b
|
||||
)
|
||||
|
||||
if defined ES_ADDITIONAL_CLASSPATH_DIRECTORIES (
|
||||
for %%a in ("%ES_ADDITIONAL_CLASSPATH_DIRECTORIES:;=","%") do (
|
||||
set ES_CLASSPATH=!ES_CLASSPATH!;!ES_HOME!/%%a/*
|
||||
|
@ -24,5 +19,5 @@ if defined ES_ADDITIONAL_CLASSPATH_DIRECTORIES (
|
|||
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
|
||||
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
|
||||
-cp "%ES_CLASSPATH%" ^
|
||||
%main_class% ^
|
||||
%arguments%
|
||||
"%ES_MAIN_CLASS%" ^
|
||||
%*
|
||||
|
|
|
@ -63,7 +63,7 @@ if [ ! -z "$JAVA_OPTS" ]; then
|
|||
fi
|
||||
|
||||
# check the Java version
|
||||
"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JavaVersionChecker
|
||||
"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.java_version_checker.JavaVersionChecker
|
||||
|
||||
export HOSTNAME=$HOSTNAME
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ if defined JAVA_OPTS (
|
|||
)
|
||||
|
||||
rem check the Java version
|
||||
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.launchers.JavaVersionChecker" || exit /b 1
|
||||
%JAVA% -cp "%ES_CLASSPATH%" "org.elasticsearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
|
||||
|
||||
set HOSTNAME=%COMPUTERNAME%
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
"`dirname "$0"`"/elasticsearch-cli \
|
||||
org.elasticsearch.common.settings.KeyStoreCli \
|
||||
ES_MAIN_CLASS=org.elasticsearch.common.settings.KeyStoreCli \
|
||||
"`dirname "$0"`"/elasticsearch-cli \
|
||||
"$@"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
setlocal enabledelayedexpansion
|
||||
setlocal enableextensions
|
||||
|
||||
set ES_MAIN_CLASS=org.elasticsearch.common.settings.KeyStoreCli
|
||||
call "%~dp0elasticsearch-cli.bat" ^
|
||||
org.elasticsearch.common.settings.KeyStoreCli ^
|
||||
%%* ^
|
||||
|| exit /b 1
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli \
|
||||
ES_MAIN_CLASS=org.elasticsearch.plugins.PluginCli \
|
||||
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli \
|
||||
"`dirname "$0"`"/elasticsearch-cli \
|
||||
org.elasticsearch.plugins.PluginCli \
|
||||
"$@"
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
setlocal enabledelayedexpansion
|
||||
setlocal enableextensions
|
||||
|
||||
set ES_MAIN_CLASS=org.elasticsearch.plugins.PluginCli
|
||||
set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli
|
||||
call "%~dp0elasticsearch-cli.bat" ^
|
||||
org.elasticsearch.plugins.PluginCli ^
|
||||
%%* ^
|
||||
|| exit /b 1
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
"`dirname "$0"`"/elasticsearch-cli \
|
||||
org.elasticsearch.index.translog.TranslogToolCli \
|
||||
ES_MAIN_CLASS=org.elasticsearch.index.translog.TranslogToolCli \
|
||||
"`dirname "$0"`"/elasticsearch-cli \
|
||||
"$@"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
setlocal enabledelayedexpansion
|
||||
setlocal enableextensions
|
||||
|
||||
set ES_MAIN_CLASS=org.elasticsearch.index.translog.TranslogToolCli
|
||||
call "%~dp0elasticsearch-cli.bat" ^
|
||||
org.elasticsearch.index.translog.TranslogToolCli ^
|
||||
%%* ^
|
||||
|| exit /b 1
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
import org.elasticsearch.gradle.precommit.PrecommitTasks
|
||||
|
||||
apply plugin: 'elasticsearch.build'
|
||||
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
|
||||
// java_version_checker do not depend on core so only JDK signatures should be checked
|
||||
forbiddenApisMain.signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
|
||||
test.enabled = false
|
||||
namingConventions.enabled = false
|
||||
javadoc.enabled = false
|
||||
loggerUsageCheck.enabled = false
|
||||
jarHell.enabled = false
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.tools.launchers;
|
||||
package org.elasticsearch.tools.java_version_checker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -25,8 +25,8 @@ import java.util.Objects;
|
|||
|
||||
public class JavaVersion {
|
||||
|
||||
static final List<Integer> CURRENT = parse(System.getProperty("java.specification.version"));
|
||||
static final List<Integer> JAVA_8 = parse("1.8");
|
||||
public static final List<Integer> CURRENT = parse(System.getProperty("java.specification.version"));
|
||||
public static final List<Integer> JAVA_8 = parse("1.8");
|
||||
|
||||
static List<Integer> parse(final String value) {
|
||||
if (!value.matches("^0*[0-9]+(\\.[0-9]+)*$")) {
|
||||
|
@ -41,7 +41,7 @@ public class JavaVersion {
|
|||
return version;
|
||||
}
|
||||
|
||||
static int majorVersion(final List<Integer> javaVersion) {
|
||||
public static int majorVersion(final List<Integer> javaVersion) {
|
||||
Objects.requireNonNull(javaVersion);
|
||||
if (javaVersion.get(0) > 1) {
|
||||
return javaVersion.get(0);
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.tools.launchers;
|
||||
package org.elasticsearch.tools.java_version_checker;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
@ -45,10 +45,30 @@ final class JavaVersionChecker {
|
|||
Locale.ROOT,
|
||||
"the minimum required Java version is 8; your Java version from [%s] does not meet this requirement",
|
||||
System.getProperty("java.home"));
|
||||
Launchers.errPrintln(message);
|
||||
Launchers.exit(1);
|
||||
errPrintln(message);
|
||||
exit(1);
|
||||
}
|
||||
Launchers.exit(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a string and terminates the line on standard error.
|
||||
*
|
||||
* @param message the message to print
|
||||
*/
|
||||
@SuppressForbidden(reason = "System#err")
|
||||
static void errPrintln(final String message) {
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit the VM with the specified status.
|
||||
*
|
||||
* @param status the status
|
||||
*/
|
||||
@SuppressForbidden(reason = "System#exit")
|
||||
static void exit(final int status) {
|
||||
System.exit(status);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,17 +17,18 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.tools.launchers;
|
||||
package org.elasticsearch.tools.java_version_checker;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to suppress forbidden-apis errors inside a whole class, a method, or a field.
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({ ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
|
||||
@interface SuppressForbidden {
|
||||
public @interface SuppressForbidden {
|
||||
String reason();
|
||||
}
|
|
@ -21,14 +21,9 @@ import org.elasticsearch.gradle.precommit.PrecommitTasks
|
|||
import org.gradle.api.JavaVersion
|
||||
|
||||
apply plugin: 'elasticsearch.build'
|
||||
apply plugin: 'ru.vyarus.animalsniffer'
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
|
||||
dependencies {
|
||||
signature "org.codehaus.mojo.signature:java17:1.0@signature"
|
||||
|
||||
compile parent.project('java-version-checker')
|
||||
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
|
||||
testCompile "junit:junit:${versions.junit}"
|
||||
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
|
||||
|
@ -36,13 +31,10 @@ dependencies {
|
|||
|
||||
archivesBaseName = 'elasticsearch-launchers'
|
||||
|
||||
// launchers do not depend on core so only JDK signatures should be checked
|
||||
forbiddenApisMain {
|
||||
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
}
|
||||
forbiddenApisTest {
|
||||
signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
}
|
||||
// java_version_checker do not depend on core so only JDK signatures should be checked
|
||||
List jdkSignatures = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')]
|
||||
forbiddenApisMain.signaturesURLs = jdkSignatures
|
||||
forbiddenApisTest.signaturesURLs = jdkSignatures
|
||||
|
||||
namingConventions {
|
||||
testClass = 'org.elasticsearch.tools.launchers.LaunchersTestCase'
|
||||
|
@ -51,4 +43,4 @@ namingConventions {
|
|||
|
||||
javadoc.enabled = false
|
||||
loggerUsageCheck.enabled = false
|
||||
jarHell.enabled=false
|
||||
jarHell.enabled = false
|
||||
|
|
|
@ -38,6 +38,8 @@ import java.util.TreeMap;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.elasticsearch.tools.java_version_checker.JavaVersion;
|
||||
|
||||
/**
|
||||
* Parses JVM options from a file and prints a single line with all JVM options to standard output.
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.elasticsearch.tools.launchers;
|
||||
|
||||
import org.elasticsearch.tools.java_version_checker.SuppressForbidden;
|
||||
|
||||
/**
|
||||
* Utility methods for launchers.
|
||||
*/
|
||||
|
|
|
@ -140,5 +140,7 @@ include::snapshot/verify_repository.asciidoc[]
|
|||
The Java High Level REST Client supports the following Tasks APIs:
|
||||
|
||||
* <<java-rest-high-tasks-list>>
|
||||
* <<java-rest-high-cluster-cancel-tasks>>
|
||||
|
||||
include::tasks/list_tasks.asciidoc[]
|
||||
include::tasks/cancel_tasks.asciidoc[]
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
[[java-rest-high-cluster-cancel-tasks]]
|
||||
=== Cancel Tasks API
|
||||
|
||||
The Cancel Tasks API allows cancellation of a currently running task.
|
||||
|
||||
==== Cancel Tasks Request
|
||||
|
||||
A `CancelTasksRequest`:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-request]
|
||||
--------------------------------------------------
|
||||
There are no required parameters. The task cancellation command supports the same
|
||||
task selection parameters as the list tasks command.
|
||||
|
||||
==== Parameters
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-request-filter]
|
||||
--------------------------------------------------
|
||||
<1> Cancel a task
|
||||
<2> Cancel only cluster-related tasks
|
||||
<3> Cancel all tasks running on nodes nodeId1 and nodeId2
|
||||
|
||||
==== Synchronous Execution
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-execute]
|
||||
--------------------------------------------------
|
||||
|
||||
==== Asynchronous Execution
|
||||
|
||||
The asynchronous execution requires `CancelTasksRequest` instance and an
|
||||
`ActionListener` instance to be passed to the asynchronous method:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-async]
|
||||
--------------------------------------------------
|
||||
<1> The `CancelTasksRequest` to execute and the `ActionListener` to use
|
||||
when the execution completes
|
||||
|
||||
The asynchronous method does not block and returns immediately. Once it is
|
||||
completed the `ActionListener` is called back using the `onResponse` method
|
||||
if the execution successfully completed or using the `onFailure` method if
|
||||
it failed.
|
||||
|
||||
A typical listener for `CancelTasksResponse` looks like:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[cancel-tasks-execute-listener]
|
||||
--------------------------------------------------
|
||||
<1> Called when the execution is successfully completed. The response is
|
||||
provided as an argument
|
||||
<2> Called in case of a failure. The raised exception is provided as an argument
|
||||
|
||||
==== Cancel Tasks Response
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-tasks]
|
||||
--------------------------------------------------
|
||||
<1> List of cancelled tasks
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-calc]
|
||||
--------------------------------------------------
|
||||
<1> List of cancelled tasks grouped by a node
|
||||
<2> List of cancelled tasks grouped by a parent task
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/TasksClientDocumentationIT.java[list-tasks-response-failures]
|
||||
--------------------------------------------------
|
||||
<1> List of node failures
|
||||
<2> List of task cancellation failures
|
||||
|
|
@ -4,8 +4,11 @@
|
|||
A cast converts the value of an original type to the equivalent value of a
|
||||
target type. An implicit cast infers the target type and automatically occurs
|
||||
during certain <<painless-operators, operations>>. An explicit cast specifies
|
||||
the target type and forcefully occurs as its own operation. Use the *cast
|
||||
operator* to specify an explicit cast.
|
||||
the target type and forcefully occurs as its own operation. Use the `cast
|
||||
operator '()'` to specify an explicit cast.
|
||||
|
||||
Refer to the <<allowed-casts, cast table>> for a quick reference on all
|
||||
allowed casts.
|
||||
|
||||
*Errors*
|
||||
|
||||
|
@ -13,6 +16,7 @@ operator* to specify an explicit cast.
|
|||
* If an implicit cast is given, but an explicit cast is required.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
cast: '(' TYPE ')' expression
|
||||
|
@ -31,15 +35,15 @@ cast: '(' TYPE ')' expression
|
|||
+
|
||||
<1> declare `int i`;
|
||||
explicit cast `long 5` to `int 5` -> `int 5`;
|
||||
assign `int 5` to `i`
|
||||
store `int 5` to `i`
|
||||
<2> declare `Map m`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
assign `Map reference` to `m`
|
||||
store `Map reference` to `m`
|
||||
<3> declare `HashMap hm`;
|
||||
access `m` -> `Map reference`;
|
||||
load from `m` -> `Map reference`;
|
||||
explicit cast `Map reference` to `HashMap reference` -> `HashMap reference`;
|
||||
assign `HashMap reference` to `hm`
|
||||
store `HashMap reference` to `hm`
|
||||
|
||||
[[numeric-type-casting]]
|
||||
==== Numeric Type Casting
|
||||
|
@ -78,19 +82,19 @@ following table:
|
|||
----
|
||||
+
|
||||
<1> declare `int a`;
|
||||
assign `int 1` to `a`
|
||||
store `int 1` to `a`
|
||||
<2> declare `long b`;
|
||||
access `a` -> `int 1`;
|
||||
load from `a` -> `int 1`;
|
||||
implicit cast `int 1` to `long 1` -> `long 1`;
|
||||
assign `long 1` to `b`
|
||||
store `long 1` to `b`
|
||||
<3> declare `short c`;
|
||||
access `b` -> `long 1`;
|
||||
load from `b` -> `long 1`;
|
||||
explicit cast `long 1` to `short 1` -> `short 1`;
|
||||
assign `short 1` value to `c`
|
||||
store `short 1` value to `c`
|
||||
<4> declare `double e`;
|
||||
access `a` -> `int 1`;
|
||||
load from `a` -> `int 1`;
|
||||
explicit cast `int 1` to `double 1.0`;
|
||||
assign `double 1.0` to `e`;
|
||||
store `double 1.0` to `e`;
|
||||
(note the explicit cast is extraneous since an implicit cast is valid)
|
||||
+
|
||||
* Invalid numeric type casts resulting in errors.
|
||||
|
@ -106,9 +110,9 @@ following table:
|
|||
*error* -> cannot implicit cast `double 1.0` to `int 1`;
|
||||
(note an explicit cast is valid)
|
||||
<2> declare `int b`;
|
||||
assign `int 2` to `b`
|
||||
store `int 2` to `b`
|
||||
<3> declare byte `c`;
|
||||
access `b` -> `int 2`;
|
||||
load from `b` -> `int 2`;
|
||||
*error* -> cannot implicit cast `int 2` to `byte 2`;
|
||||
(note an explicit cast is valid)
|
||||
|
||||
|
@ -136,21 +140,21 @@ or the target type is a descendant of the original type.
|
|||
----
|
||||
+
|
||||
<1> declare `List x`;
|
||||
assign default value `null` to `x`
|
||||
store default value `null` to `x`
|
||||
<2> declare `ArrayList y`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
assign `ArrayList reference` to `y`;
|
||||
<3> access `y` -> `ArrayList reference`;
|
||||
store `ArrayList reference` to `y`;
|
||||
<3> load from `y` -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `x`;
|
||||
store `List reference` to `x`;
|
||||
(note `ArrayList` is a descendant of `List`)
|
||||
<4> access `x` -> `List reference`;
|
||||
<4> load from `x` -> `List reference`;
|
||||
explicit cast `List reference` to `ArrayList reference`
|
||||
-> `ArrayList reference`;
|
||||
assign `ArrayList reference` to `y`;
|
||||
<5> access `y` -> `ArrayList reference`;
|
||||
store `ArrayList reference` to `y`;
|
||||
<5> load from `y` -> `ArrayList reference`;
|
||||
explicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `x`;
|
||||
store `List reference` to `x`;
|
||||
(note the explicit cast is extraneous, and an implicit cast is valid)
|
||||
+
|
||||
* Invalid reference type casts resulting in errors.
|
||||
|
@ -165,16 +169,16 @@ or the target type is a descendant of the original type.
|
|||
<1> declare `List x`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `x`
|
||||
store `List reference` to `x`
|
||||
<2> declare `ArrayList y`;
|
||||
access `x` -> `List reference`;
|
||||
load from `x` -> `List reference`;
|
||||
*error* -> cannot implicit cast `List reference` to `ArrayList reference`;
|
||||
(note an explicit cast is valid since `ArrayList` is a descendant of `List`)
|
||||
<3> declare `ArrayList y`;
|
||||
access `x` -> `List reference`;
|
||||
load from `x` -> `List reference`;
|
||||
*error* -> cannot explicit cast `List reference` to `Map reference`;
|
||||
(note no cast would be valid since neither `List` nor `Map` is a descendant
|
||||
of the other)
|
||||
(note no cast is valid since neither `List` nor `Map` is a descendant of the
|
||||
other)
|
||||
|
||||
[[dynamic-type-casting]]
|
||||
==== Dynamic Type Casting
|
||||
|
@ -206,24 +210,24 @@ based on the current type value the `def` type value represents.
|
|||
+
|
||||
<1> declare `def d0`;
|
||||
implicit cast `int 3` to `def`;
|
||||
assign `int 3` to `d0`
|
||||
store `int 3` to `d0`
|
||||
<2> allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `def` -> `def`;
|
||||
assign `def` to `d0`
|
||||
store `def` to `d0`
|
||||
<3> declare `Object o`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Object reference`
|
||||
-> `Object reference`;
|
||||
assign `Object reference` to `o`
|
||||
store `Object reference` to `o`
|
||||
<4> declare `def d1`;
|
||||
access `o` -> `Object reference`;
|
||||
load from `o` -> `Object reference`;
|
||||
implicit cast `Object reference` to `def` -> `def`;
|
||||
assign `def` to `d1`
|
||||
store `def` to `d1`
|
||||
<5> declare `int i`;
|
||||
access `d1` -> `def`;
|
||||
load from `d1` -> `def`;
|
||||
implicit cast `def` to `HashMap reference` -> HashMap reference`;
|
||||
call `size` on `HashMap reference` -> `int 0`;
|
||||
assign `int 0` to `i`;
|
||||
store `int 0` to `i`;
|
||||
(note `def` was implicit cast to `HashMap reference` since `HashMap` is the
|
||||
child-most descendant type value that the `def` type value
|
||||
represents)
|
||||
|
@ -242,29 +246,29 @@ based on the current type value the `def` type value represents.
|
|||
+
|
||||
<1> declare `def d`;
|
||||
implicit cast `double 1.0` to `def` -> `def`;
|
||||
assign `def` to `d`
|
||||
store `def` to `d`
|
||||
<2> declare `int i`;
|
||||
access `d` -> `def`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `double 1.0` -> `double 1.0`;
|
||||
explicit cast `double 1.0` to `int 1` -> `int 1`;
|
||||
assign `int 1` to `i`;
|
||||
(note the explicit cast is necessary since a `double` value cannot be
|
||||
converted to an `int` value implicitly)
|
||||
<3> assign `int 1` to `d`;
|
||||
store `int 1` to `i`;
|
||||
(note the explicit cast is necessary since a `double` type value is not
|
||||
converted to an `int` type value implicitly)
|
||||
<3> store `int 1` to `d`;
|
||||
(note the switch in the type `d` represents from `double` to `int`)
|
||||
<4> declare `float i`;
|
||||
access `d` -> `def`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
implicit cast `int 1` to `float 1.0` -> `float 1.0`;
|
||||
assign `float 1.0` to `f`
|
||||
store `float 1.0` to `f`
|
||||
<5> allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
assign `ArrayList reference` to `d`;
|
||||
store `ArrayList reference` to `d`;
|
||||
(note the switch in the type `d` represents from `int` to `ArrayList`)
|
||||
<6> declare `List l`;
|
||||
access `d` -> `def`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `l`
|
||||
store `List reference` to `l`
|
||||
+
|
||||
* Invalid dynamic type casts resulting in errors.
|
||||
+
|
||||
|
@ -277,26 +281,26 @@ based on the current type value the `def` type value represents.
|
|||
----
|
||||
<1> declare `def d`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
assign `def` to `d`
|
||||
store `def` to `d`
|
||||
<2> declare `short s`;
|
||||
access `d` -> `def`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
*error* -> cannot implicit cast `int 1` to `short 1`;
|
||||
(note an explicit cast is valid)
|
||||
<3> allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `def` -> `def`;
|
||||
assign `def` to `d`
|
||||
store `def` to `d`
|
||||
<4> declare `List l`;
|
||||
access `d` -> `def`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `HashMap reference`;
|
||||
*error* -> cannot implicit cast `HashMap reference` to `List reference`;
|
||||
(note no cast would be valid since neither `HashMap` nor `List` is a
|
||||
descendant of the other)
|
||||
(note no cast is valid since neither `HashMap` nor `List` is a descendant of
|
||||
the other)
|
||||
|
||||
[[string-character-casting]]
|
||||
==== String to Character Casting
|
||||
|
||||
Use the *cast operator* to convert a <<string-type, `String` type>> value into a
|
||||
Use the cast operator to convert a <<string-type, `String` type>> value into a
|
||||
<<primitive-types, `char` type>> value.
|
||||
|
||||
*Errors*
|
||||
|
@ -310,17 +314,17 @@ Use the *cast operator* to convert a <<string-type, `String` type>> value into a
|
|||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> char c = (char)"C"
|
||||
<2> c = (char)'c'
|
||||
<1> char c = (char)"C";
|
||||
<2> c = (char)'c';
|
||||
----
|
||||
+
|
||||
<1> declare `char c`;
|
||||
explicit cast `String "C"` to `char C` -> `char C`;
|
||||
assign `char C` to `c`
|
||||
store `char C` to `c`
|
||||
<2> explicit cast `String 'c'` to `char c` -> `char c`;
|
||||
assign `char c` to `c`
|
||||
store `char c` to `c`
|
||||
+
|
||||
* Casting a `String` reference into a `char` value.
|
||||
* Casting a `String` reference into a `char` type value.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -328,11 +332,11 @@ Use the *cast operator* to convert a <<string-type, `String` type>> value into a
|
|||
<2> char c = (char)s;
|
||||
----
|
||||
<1> declare `String s`;
|
||||
assign `String "s"` to `s`;
|
||||
store `String "s"` to `s`;
|
||||
<2> declare `char c`
|
||||
access `s` -> `String "s"`;
|
||||
load from `s` -> `String "s"`;
|
||||
explicit cast `String "s"` to `char s` -> `char s`;
|
||||
assign `char s` to `c`
|
||||
store `char s` to `c`
|
||||
|
||||
[[boxing-unboxing]]
|
||||
==== Boxing and Unboxing
|
||||
|
@ -343,12 +347,12 @@ reference type to its corresponding primitive type.
|
|||
|
||||
Implicit boxing/unboxing occurs during the following operations:
|
||||
|
||||
* Conversions between a `def` type and a primitive type will be implicitly
|
||||
* Conversions between a `def` type and a primitive type are implicitly
|
||||
boxed/unboxed as necessary, though this is referred to as an implicit cast
|
||||
throughout the documentation.
|
||||
* Method/function call arguments will be implicitly boxed/unboxed as necessary.
|
||||
* A primitive type value will be implicitly boxed when a reference type method
|
||||
call is invoked on it.
|
||||
* Method/function call arguments are implicitly boxed/unboxed as necessary.
|
||||
* A primitive type value is implicitly boxed when a reference type method
|
||||
is called on it.
|
||||
|
||||
Explicit boxing/unboxing is not allowed. Use the reference type API to
|
||||
explicitly convert a primitive type value to its respective reference type
|
||||
|
@ -372,22 +376,22 @@ value and vice versa.
|
|||
+
|
||||
<1> declare `List l`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
assign `ArrayList reference` to `l`;
|
||||
<2> access `l` -> `List reference`;
|
||||
store `ArrayList reference` to `l`;
|
||||
<2> load from `l` -> `List reference`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
call `add` on `List reference` with arguments (`def`);
|
||||
(note internally `int 1` is boxed to `Integer 1` to store as a `def` type
|
||||
value)
|
||||
<3> declare `Integer I`;
|
||||
call `valueOf` on `Integer` with arguments of (`int 0`) -> `Integer 0`;
|
||||
assign `Integer 0` to `I`;
|
||||
store `Integer 0` to `I`;
|
||||
<4> declare `int i`;
|
||||
access `I` -> `Integer 0`;
|
||||
load from `I` -> `Integer 0`;
|
||||
unbox `Integer 0` -> `int 0`;
|
||||
access `l` -> `List reference`;
|
||||
load from `l` -> `List reference`;
|
||||
call `get` on `List reference` with arguments (`int 0`) -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
assign `int 1` to `i`;
|
||||
store `int 1` to `i`;
|
||||
(note internally `int 1` is unboxed from `Integer 1` when loaded from a
|
||||
`def` type value)
|
||||
+
|
||||
|
@ -419,8 +423,8 @@ Promotion is when a single value is implicitly cast to a certain type or
|
|||
multiple values are implicitly cast to the same type as required for evaluation
|
||||
by certain operations. Each operation that requires promotion has a promotion
|
||||
table that shows all required implicit casts based on the type(s) of value(s). A
|
||||
value can be promoted to a `def` type at compile-time; however, the promoted
|
||||
type value is derived from what the `def` type value represents at run-time.
|
||||
value promoted to a `def` type at compile-time is promoted again at run-time
|
||||
based on the type the `def` value represents.
|
||||
|
||||
*Errors*
|
||||
|
||||
|
@ -438,19 +442,83 @@ type value is derived from what the `def` type value represents at run-time.
|
|||
<3> float f = x + 2.0F;
|
||||
----
|
||||
<1> declare `double d`;
|
||||
promote `int 2` and `double 2.0 @0` -> `double 2.0 @0`;
|
||||
promote `int 2` and `double 2.0 @0`: result `double`;
|
||||
implicit cast `int 2` to `double 2.0 @1` -> `double 2.0 @1`;
|
||||
add `double 2.0 @1` and `double 2.0 @0` -> `double 4.0`;
|
||||
assign `double 4.0` to `d`
|
||||
store `double 4.0` to `d`
|
||||
<2> declare `def x`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
assign `def` to `x`;
|
||||
store `def` to `x`;
|
||||
<3> declare `float f`;
|
||||
access `x` -> `def`;
|
||||
load from `x` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
promote `int 1` and `float 2.0` -> `float 2.0`;
|
||||
promote `int 1` and `float 2.0`: result `float`;
|
||||
implicit cast `int 1` to `float 1.0` -> `float `1.0`;
|
||||
add `float 1.0` and `float 2.0` -> `float 3.0`;
|
||||
assign `float 3.0` to `f`;
|
||||
store `float 3.0` to `f`;
|
||||
(note this example illustrates promotion done at run-time as promotion
|
||||
done at compile-time would have resolved to a `def` type value)
|
||||
|
||||
[[allowed-casts]]
|
||||
==== Allowed Casts
|
||||
|
||||
The following tables show all allowed casts. Read the tables row by row, where
|
||||
the original type is shown in the first column, and each subsequent column
|
||||
indicates whether a cast to the specified target type is implicit (I), explicit
|
||||
(E), or is not allowed (-).
|
||||
|
||||
*Primitive/Reference Types*
|
||||
|
||||
[cols="<3,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1"]
|
||||
|====
|
||||
| | o | b | s | c | i | j | f | d | O | B | S | C | I | L | F | D | T | R | def
|
||||
| boolean ( o ) | | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | I
|
||||
| byte ( b ) | - | | I | I | I | I | I | I | - | - | - | - | - | - | - | - | - | - | I
|
||||
| short ( s ) | - | E | | E | I | I | I | I | - | - | - | - | - | - | - | - | - | - | I
|
||||
| char ( c ) | - | E | E | | I | I | I | I | - | - | - | - | - | - | - | - | E | - | I
|
||||
| int ( i ) | - | E | E | E | | I | I | I | - | - | - | - | - | - | - | - | - | - | I
|
||||
| long ( j ) | - | E | E | E | E | | I | I | - | - | - | - | - | - | - | - | - | - | I
|
||||
| float ( f ) | - | E | E | E | E | E | | I | - | - | - | - | - | - | - | - | - | - | I
|
||||
| double ( d ) | - | E | E | E | E | E | E | | - | - | - | - | - | - | - | - | - | - | I
|
||||
| Boolean ( O ) | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | I
|
||||
| Byte ( B ) | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | - | - | I
|
||||
| Short ( S ) | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | - | I
|
||||
| Character ( C ) | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | I
|
||||
| Integer ( I ) | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | I
|
||||
| Long ( L ) | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | I
|
||||
| Float ( F ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | I
|
||||
| Double ( D ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | I
|
||||
| String ( T ) | - | - | - | E | - | - | - | - | - | - | - | - | - | - | - | - | | - | I
|
||||
| Reference ( R ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | @ | I
|
||||
|====
|
||||
|
||||
@ See <<reference-type-casting, reference type casting>> for allowed reference
|
||||
type casts.
|
||||
|
||||
*`def` Type*
|
||||
|
||||
[cols="<3,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1"]
|
||||
|====
|
||||
| | o | b | s | c | i | j | f | d | O | B | S | C | I | L | F | D | T | R | def
|
||||
| def as boolean | I | - | - | - | - | - | - | - | I | - | - | - | - | - | - | - | - | - |
|
||||
| def as byte | - | I | I | I | I | I | I | I | - | I | I | I | I | I | I | I | - | - |
|
||||
| def as short | - | E | I | E | I | I | I | I | - | E | I | E | I | I | I | I | - | - |
|
||||
| def as char | - | E | E | I | I | I | I | I | - | E | E | I | I | I | I | I | E | - |
|
||||
| def as int | - | E | E | E | I | I | I | I | - | E | E | E | I | I | I | I | - | - |
|
||||
| def as long | - | E | E | E | E | I | I | I | - | E | E | E | E | I | I | I | - | - |
|
||||
| def as float | - | E | E | E | E | E | I | I | - | E | E | E | E | E | I | I | - | - |
|
||||
| def as double | - | E | E | E | E | E | E | I | - | E | E | E | E | E | E | I | - | - |
|
||||
| def as Boolean | I | - | - | - | - | - | - | - | I | - | - | - | | - | - | - | - | - |
|
||||
| def as Byte | - | I | I | I | I | I | I | I | - | I | I | I | I | I | I | I | - | - |
|
||||
| def as Short | - | E | I | E | I | I | I | I | - | E | I | E | I | I | I | I | - | - |
|
||||
| def as Character | - | E | E | I | I | I | I | I | - | E | E | I | I | I | I | I | - | - |
|
||||
| def as Integer | - | E | E | E | I | I | I | I | - | E | E | E | I | I | I | I | - | - |
|
||||
| def as Long | - | E | E | E | E | I | I | I | - | E | E | E | E | I | I | I | - | - |
|
||||
| def as Float | - | E | E | E | E | E | I | I | - | E | E | E | E | E | I | I | - | - |
|
||||
| def as Double | - | E | E | E | E | E | E | I | - | E | E | E | E | E | E | I | - | - |
|
||||
| def as String | - | - | - | E | - | - | - | - | - | - | - | - | - | - | - | - | I | - |
|
||||
| def as Reference | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | @ |
|
||||
|====
|
||||
|
||||
@ See <<reference-type-casting, reference type casting>> for allowed reference
|
||||
type casts.
|
||||
|
|
|
@ -6,9 +6,10 @@ anywhere on a line to specify a single-line comment. All characters from the
|
|||
`//` token to the end of the line are ignored. Use an opening `/*` token and a
|
||||
closing `*/` token to specify a multi-line comment. Multi-line comments can
|
||||
start anywhere on a line, and all characters in between the `/*` token and `*/`
|
||||
token are ignored. Comments can be included anywhere within a script.
|
||||
token are ignored. A comment is included anywhere within a script.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
SINGLE_LINE_COMMENT: '//' .*? [\n\r];
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
[[painless-functions]]
|
||||
=== Functions
|
||||
|
||||
A function is a named piece of code comprised of one-to-many statements to
|
||||
perform a specific task. A function is called multiple times in a single script
|
||||
to repeat its specific task. A parameter is a named type value available as a
|
||||
<<painless-variables, variable>> within the statement(s) of a function. A
|
||||
function specifies zero-to-many parameters, and when a function is called a
|
||||
value is specified per parameter. An argument is a value passed into a function
|
||||
at the point of call. A function specifies a return type value, though if the
|
||||
type is <<void-type, void>> then no value is returned. Any non-void type return
|
||||
value is available for use within an <<painless-operators, operation>> or is
|
||||
discarded otherwise.
|
||||
|
||||
You can declare functions at the beginning of a Painless script, for example:
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
boolean isNegative(def x) { x < 0 }
|
||||
...
|
||||
if (isNegative(someVar)) {
|
||||
...
|
||||
}
|
||||
---------------------------------------------------------
|
|
@ -1,81 +0,0 @@
|
|||
[[painless-general-syntax]]
|
||||
=== General Syntax
|
||||
|
||||
[[control-flow]]
|
||||
==== Control flow
|
||||
|
||||
Painless supports all of Java's https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html[
|
||||
control flow statements] except the `switch` statement.
|
||||
|
||||
Painless also supports the `for in` syntax from Groovy:
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
for (item : list) {
|
||||
...
|
||||
}
|
||||
---------------------------------------------------------
|
||||
|
||||
[[functions]]
|
||||
==== Functions
|
||||
|
||||
You can declare functions at the beginning of a Painless script, for example:
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
boolean isNegative(def x) { x < 0 }
|
||||
...
|
||||
if (isNegative(someVar)) {
|
||||
...
|
||||
}
|
||||
---------------------------------------------------------
|
||||
|
||||
[[lambda-expressions]]
|
||||
==== Lambda expressions
|
||||
Lambda expressions and method references work the same as in https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Java].
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
list.removeIf(item -> item == 2);
|
||||
list.removeIf((int item) -> item == 2);
|
||||
list.removeIf((int item) -> { item == 2 });
|
||||
list.sort((x, y) -> x - y);
|
||||
list.sort(Integer::compare);
|
||||
---------------------------------------------------------
|
||||
|
||||
You can make method references to functions within the script with `this`,
|
||||
for example `list.sort(this::mycompare)`.
|
||||
|
||||
[[patterns]]
|
||||
==== Patterns
|
||||
|
||||
Regular expression constants are directly supported. To ensure fast performance,
|
||||
this is the only mechanism for creating patterns. Regular expressions
|
||||
are always constants and compiled efficiently a single time.
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
Pattern p = /[aeiou]/
|
||||
---------------------------------------------------------
|
||||
|
||||
[[pattern-flags]]
|
||||
===== Pattern flags
|
||||
|
||||
You can define flags on patterns in Painless by adding characters after the
|
||||
trailing `/` like `/foo/i` or `/foo \w #comment/iUx`. Painless exposes all of
|
||||
the flags from Java's
|
||||
https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html[
|
||||
Pattern class] using these characters:
|
||||
|
||||
[cols="<,<,<",options="header",]
|
||||
|=======================================================================
|
||||
| Character | Java Constant | Example
|
||||
|`c` | CANON_EQ | `'å' ==~ /å/c` (open in hex editor to see)
|
||||
|`i` | CASE_INSENSITIVE | `'A' ==~ /a/i`
|
||||
|`l` | LITERAL | `'[a]' ==~ /[a]/l`
|
||||
|`m` | MULTILINE | `'a\nb\nc' =~ /^b$/m`
|
||||
|`s` | DOTALL (aka single line) | `'a\nb\nc' =~ /.b./s`
|
||||
|`U` | UNICODE_CHARACTER_CLASS | `'Ɛ' ==~ /\\w/U`
|
||||
|`u` | UNICODE_CASE | `'Ɛ' ==~ /ɛ/iu`
|
||||
|`x` | COMMENTS (aka extended) | `'a' ==~ /a #comment/x`
|
||||
|=======================================================================
|
|
@ -3,8 +3,12 @@
|
|||
|
||||
Use an identifier as a named token to specify a
|
||||
<<painless-variables, variable>>, <<painless-types, type>>,
|
||||
<<dot-operator, field>>, <<dot-operator, method>>, or function.
|
||||
<<painless-keywords, Keywords>> cannot be used as identifiers.
|
||||
<<field-access-operator, field>>, <<method-call-operator, method>>, or
|
||||
<<painless-functions, function>>.
|
||||
|
||||
*Errors*
|
||||
|
||||
If a <<painless-keywords, keyword>> is used as an identifier.
|
||||
|
||||
*Grammar*
|
||||
[source,ANTLR4]
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
[[painless-keywords]]
|
||||
=== Keywords
|
||||
|
||||
Keywords are reserved tokens for built-in language features and cannot be used
|
||||
as <<painless-identifiers, identifiers>> within a script. The following are
|
||||
keywords:
|
||||
Keywords are reserved tokens for built-in language features.
|
||||
|
||||
*Errors*
|
||||
|
||||
If a keyword is used as an <<painless-identifiers, identifier>>.
|
||||
|
||||
*Keywords*
|
||||
|
||||
[cols="^1,^1,^1,^1,^1"]
|
||||
|====
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
[[painless-lambdas]]
|
||||
=== Lambdas
|
||||
Lambda expressions and method references work the same as in https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Java].
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
list.removeIf(item -> item == 2);
|
||||
list.removeIf((int item) -> item == 2);
|
||||
list.removeIf((int item) -> { item == 2 });
|
||||
list.sort((x, y) -> x - y);
|
||||
list.sort(Integer::compare);
|
||||
---------------------------------------------------------
|
||||
|
||||
You can make method references to functions within the script with `this`,
|
||||
for example `list.sort(this::mycompare)`.
|
|
@ -33,4 +33,22 @@ include::painless-casting.asciidoc[]
|
|||
|
||||
include::painless-operators.asciidoc[]
|
||||
|
||||
include::painless-general-syntax.asciidoc[]
|
||||
include::painless-operators-general.asciidoc[]
|
||||
|
||||
include::painless-operators-numeric.asciidoc[]
|
||||
|
||||
include::painless-operators-boolean.asciidoc[]
|
||||
|
||||
include::painless-operators-reference.asciidoc[]
|
||||
|
||||
include::painless-operators-array.asciidoc[]
|
||||
|
||||
include::painless-statements.asciidoc[]
|
||||
|
||||
include::painless-scripts.asciidoc[]
|
||||
|
||||
include::painless-functions.asciidoc[]
|
||||
|
||||
include::painless-lambdas.asciidoc[]
|
||||
|
||||
include::painless-regexes.asciidoc[]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
Use a literal to specify a value directly in an
|
||||
<<painless-operators, operation>>.
|
||||
|
||||
[[integers]]
|
||||
[[integer-literals]]
|
||||
==== Integers
|
||||
|
||||
Use an integer literal to specify an integer type value in decimal, octal, or
|
||||
|
@ -16,6 +16,7 @@ to specify an integer literal as octal, and use `0x` or `0X` as a prefix to
|
|||
specify an integer literal as hex.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
INTEGER: '-'? ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
|
||||
|
@ -44,7 +45,7 @@ HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?;
|
|||
<5> `int -18` in octal
|
||||
<6> `int 3882` in hex
|
||||
|
||||
[[floats]]
|
||||
[[float-literals]]
|
||||
==== Floats
|
||||
|
||||
Use a floating point literal to specify a floating point type value of a
|
||||
|
@ -53,6 +54,7 @@ single letter designations to specify the primitive type: `f` or `F` for `float`
|
|||
and `d` or `D` for `double`. If not specified, the type defaults to `double`.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
DECIMAL: '-'? ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? EXPONENT? [fFdD]?;
|
||||
|
@ -78,7 +80,7 @@ EXPONENT: ( [eE] [+\-]? [0-9]+ );
|
|||
<4> `double -126.34`
|
||||
<5> `float 89.9`
|
||||
|
||||
[[strings]]
|
||||
[[string-literals]]
|
||||
==== Strings
|
||||
|
||||
Use a string literal to specify a <<string-type, `String` type>> value with
|
||||
|
@ -88,6 +90,7 @@ include a single-quote as part of a single-quoted string literal. Use a `\\`
|
|||
token to include a backslash as part of any string literal.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
|
||||
|
@ -114,9 +117,9 @@ STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' )
|
|||
"double-quoted with non-escaped 'single-quotes'"
|
||||
----
|
||||
|
||||
[[characters]]
|
||||
[[character-literals]]
|
||||
==== Characters
|
||||
|
||||
A character literal cannot be specified directly. Instead, use the
|
||||
Character literals are not specified directly. Instead, use the
|
||||
<<string-character-casting, cast operator>> to convert a `String` type value
|
||||
into a `char` type value.
|
||||
|
|
|
@ -0,0 +1,294 @@
|
|||
[[painless-operators-array]]
|
||||
=== Operators: Array
|
||||
|
||||
[[array-initialization-operator]]
|
||||
==== Array Initialization
|
||||
|
||||
Use the `array initialization operator '[] {}'` to allocate a single-dimensional
|
||||
<<array-type, array type>> instance to the heap with a set of pre-defined
|
||||
elements. Each value used to initialize an element in the array type instance is
|
||||
cast to the specified element type value upon insertion. The order of specified
|
||||
values is maintained.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a value is not castable to the specified type value.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
array_initialization: 'new' TYPE '[' ']' '{' expression_list '}'
|
||||
| 'new' TYPE '[' ']' '{' '}';
|
||||
expression_list: expression (',' expression);
|
||||
----
|
||||
|
||||
*Example:*
|
||||
|
||||
* Array initialization with static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int[] x = new int[] {1, 2, 3};
|
||||
----
|
||||
+
|
||||
<1> declare `int[] x`;
|
||||
allocate `1-d int array` instance with `length [3]`
|
||||
-> `1-d int array reference`;
|
||||
store `int 1` to `index [0]` of `1-d int array reference`;
|
||||
store `int 2` to `index [1]` of `1-d int array reference`;
|
||||
store `int 3` to `index [2]` of `1-d int array reference`;
|
||||
store `1-d int array reference` to `x`;
|
||||
+
|
||||
* Array initialization with non-static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int i = 1;
|
||||
<2> long l = 2L;
|
||||
<3> float f = 3.0F;
|
||||
<4> double d = 4.0;
|
||||
<5> String s = "5";
|
||||
<6> def array = new def[] {i, l, f*d, s};
|
||||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
store `int 1` to `i`
|
||||
<2> declare `long l`;
|
||||
store `long 2` to `l`
|
||||
<3> declare `float f`;
|
||||
store `float 3.0` to `f`
|
||||
<4> declare `double d`;
|
||||
store `double 4.0` to `d`
|
||||
<5> declare `String s`;
|
||||
store `String "5"` to `s`
|
||||
<6> declare `def array`;
|
||||
allocate `1-d def array` instance with `length [4]`
|
||||
-> `1-d def array reference`;
|
||||
load from `i` -> `int 1`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
store `def` to `index [0]` of `1-d def array reference`;
|
||||
load from `l` -> `long 2`;
|
||||
implicit cast `long 2` to `def` -> `def`;
|
||||
store `def` to `index [1]` of `1-d def array reference`;
|
||||
load from `f` -> `float 3.0`;
|
||||
load from `d` -> `double 4.0`;
|
||||
promote `float 3.0` and `double 4.0`: result `double`;
|
||||
implicit cast `float 3.0` to `double 3.0` -> `double 3.0`;
|
||||
multiply `double 3.0` and `double 4.0` -> `double 12.0`;
|
||||
implicit cast `double 12.0` to `def` -> `def`;
|
||||
store `def` to `index [2]` of `1-d def array reference`;
|
||||
load from `s` -> `String "5"`;
|
||||
implicit cast `String "5"` to `def` -> `def`;
|
||||
store `def` to `index [3]` of `1-d def array reference`;
|
||||
implicit cast `1-d int array reference` to `def` -> `def`;
|
||||
store `def` to `array`
|
||||
|
||||
[[array-access-operator]]
|
||||
==== Array Access
|
||||
|
||||
Use the `array access operator '[]'` to store a value to or load a value from
|
||||
an <<array-type, array type>> value. Each element of an array type value is
|
||||
accessed with an `int` type value to specify the index to store/load. The range
|
||||
of elements within an array that are accessible is `[0, size)` where size is the
|
||||
number of elements specified at the time of allocation. Use a negative `int`
|
||||
type value as an index to access an element in reverse from the end of an array
|
||||
type value within a range of `[-size, -1]`.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a value other than an `int` type value or a value that is castable to an
|
||||
`int` type value is provided as an index.
|
||||
* If an element is accessed outside of the valid ranges.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
brace_access: '[' expression ']'
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Array access with a single-dimensional array.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int[] x = new int[2];
|
||||
<2> x[0] = 2;
|
||||
<3> x[1] = 5;
|
||||
<4> int y = x[0] + x[1];
|
||||
<5> int z = 1;
|
||||
<6> int i = x[z];
|
||||
----
|
||||
+
|
||||
<1> declare `int[] x`;
|
||||
allocate `1-d int array` instance with `length [2]`
|
||||
-> `1-d int array reference`;
|
||||
store `1-d int array reference` to `x`
|
||||
<2> load from `x` -> `1-d int array reference`;
|
||||
store `int 2` to `index [0]` of `1-d int array reference`;
|
||||
<3> load from `x` -> `1-d int array reference`;
|
||||
store `int 5` to `index [1]` of `1-d int array reference`;
|
||||
<4> declare `int y`;
|
||||
load from `x` -> `1-d int array reference`;
|
||||
load from `index [0]` of `1-d int array reference` -> `int 2`;
|
||||
load from `x` -> `1-d int array reference`;
|
||||
load from `index [1]` of `1-d int array reference` -> `int 5`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
store `int 7` to `y`
|
||||
<5> declare `int z`;
|
||||
store `int 1` to `z`;
|
||||
<6> declare `int i`;
|
||||
load from `x` -> `1-d int array reference`;
|
||||
load from `z` -> `int 1`;
|
||||
load from `index [1]` of `1-d int array reference` -> `int 5`;
|
||||
store `int 5` to `i`;
|
||||
+
|
||||
* Array access with the `def` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> def d = new int[2];
|
||||
<2> d[0] = 2;
|
||||
<3> d[1] = 5;
|
||||
<4> def x = d[0] + d[1];
|
||||
<5> def y = 1;
|
||||
<6> def z = d[y];
|
||||
----
|
||||
+
|
||||
<1> declare `def d`;
|
||||
allocate `1-d int array` instance with `length [2]`
|
||||
-> `1-d int array reference`;
|
||||
implicit cast `1-d int array reference` to `def` -> `def`;
|
||||
store `def` to `d`
|
||||
<2> load from `d` -> `def`
|
||||
implicit cast `def` to `1-d int array reference`
|
||||
-> `1-d int array reference`;
|
||||
store `int 2` to `index [0]` of `1-d int array reference`;
|
||||
<3> load from `d` -> `def`
|
||||
implicit cast `def` to `1-d int array reference`
|
||||
-> `1-d int array reference`;
|
||||
store `int 5` to `index [1]` of `1-d int array reference`;
|
||||
<4> declare `int x`;
|
||||
load from `d` -> `def`
|
||||
implicit cast `def` to `1-d int array reference`
|
||||
-> `1-d int array reference`;
|
||||
load from `index [0]` of `1-d int array reference` -> `int 2`;
|
||||
load from `d` -> `def`
|
||||
implicit cast `def` to `1-d int array reference`
|
||||
-> `1-d int array reference`;
|
||||
load from `index [1]` of `1-d int array reference` -> `int 5`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
implicit cast `int 7` to `def` -> `def`;
|
||||
store `def` to `x`
|
||||
<5> declare `def y`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
store `def ` to `y`;
|
||||
<6> declare `int i`;
|
||||
load from `d` -> `def`
|
||||
implicit cast `def` to `1-d int array reference`
|
||||
-> `1-d int array reference`;
|
||||
load from `y` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
load from `index [1]` of `1-d int array reference` -> `int 5`;
|
||||
implicit cast `int 5` to `def`;
|
||||
store `def` to `z`;
|
||||
+
|
||||
* Array access with a multi-dimensional array.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int[][][] ia3 = new int[2][3][4];
|
||||
<2> ia3[1][2][3] = 99;
|
||||
<3> int i = ia3[1][2][3];
|
||||
----
|
||||
+
|
||||
<1> declare `int[][][] ia`;
|
||||
allocate `3-d int array` instance with length `[2, 3, 4]`
|
||||
-> `3-d int array reference`;
|
||||
store `3-d int array reference` to `ia3`
|
||||
<2> load from `ia3` -> `3-d int array reference`;
|
||||
store `int 99` to `index [1, 2, 3]` of `3-d int array reference`
|
||||
<3> declare `int i`;
|
||||
load from `ia3` -> `3-d int array reference`;
|
||||
load from `index [1, 2, 3]` of `3-d int array reference` -> `int 99`;
|
||||
store `int 99` to `i`
|
||||
|
||||
[[array-length-operator]]
|
||||
==== Array Length
|
||||
|
||||
An array type value contains a read-only member field named `length`. The
|
||||
`length` field stores the size of the array as an `int` type value where size is
|
||||
the number of elements specified at the time of allocation. Use the
|
||||
<<field-access-operator, field access operator>> to load the field `length`
|
||||
from an array type value.
|
||||
|
||||
*Examples*
|
||||
|
||||
* Access the `length` field.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int[] x = new int[10];
|
||||
<2> int l = x.length;
|
||||
----
|
||||
<1> declare `int[] x`;
|
||||
allocate `1-d int array` instance with `length [2]`
|
||||
-> `1-d int array reference`;
|
||||
store `1-d int array reference` to `x`
|
||||
<2> declare `int l`;
|
||||
load `x` -> `1-d int array reference`;
|
||||
load `length` from `1-d int array reference` -> `int 10`;
|
||||
store `int 10` to `l`;
|
||||
|
||||
[[new-array-operator]]
|
||||
==== New Array
|
||||
|
||||
Use the `new array operator 'new []'` to allocate an array type instance to
|
||||
the heap. Specify the element type following the `new` token. Specify each
|
||||
dimension with the `[` and `]` tokens following the element type name. The size
|
||||
of each dimension is specified by an `int` type value in between each set of `[`
|
||||
and `]` tokens.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a value other than an `int` type value or a value that is castable to an
|
||||
`int` type value is specified for for a dimension's size.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
new_array: 'new' TYPE ('[' expression ']')+;
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Allocation of different array types.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int[] x = new int[5];
|
||||
<2> x = new int[10];
|
||||
<3> int y = 2;
|
||||
<4> def z = new def[y][y*2];
|
||||
----
|
||||
+
|
||||
<1> declare `int[] x`;
|
||||
allocate `1-d int array` instance with `length [5]`
|
||||
-> `1-d int array reference`;
|
||||
store `1-d int array reference` to `x`
|
||||
<2> allocate `1-d int array` instance with `length [10]`
|
||||
-> `1-d int array reference`;
|
||||
store `1-d int array reference` to `x`
|
||||
<3> declare `int y`;
|
||||
store `int 2` to `y`;
|
||||
<4> declare `def z`;
|
||||
load from `y` -> `int 2 @0`;
|
||||
load from `y` -> `int 2 @1`;
|
||||
multiply `int 2 @1` by `int 2 @2` -> `int 4`;
|
||||
allocate `2-d int array` instance with length `[2, 4]`
|
||||
-> `2-d int array reference`;
|
||||
implicit cast `2-d int array reference` to `def` -> `def`;
|
||||
store `def` to `z`;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,432 @@
|
|||
[[painless-operators-general]]
|
||||
=== Operators: General
|
||||
|
||||
[[precedence-operator]]
|
||||
==== Precedence
|
||||
|
||||
Use the `precedence operator '()'` to guarantee the order of evaluation for an
|
||||
expression. An expression encapsulated by the precedence operator (enclosed in
|
||||
parentheses) overrides existing precedence relationships between operators and
|
||||
is evaluated prior to other expressions in inward-to-outward order.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
precedence: '(' expression ')';
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Precedence with numeric operators.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int x = (5+4)*6;
|
||||
<2> int y = 12/(x-50);
|
||||
----
|
||||
+
|
||||
<1> declare `int x`;
|
||||
add `int 5` and `int 4` -> `int 9`;
|
||||
multiply `int 9` and `int 6` -> `int 54`;
|
||||
store `int 54` to `x`;
|
||||
(note the add is evaluated before the multiply due to the precedence
|
||||
operator)
|
||||
<2> declare `int y`;
|
||||
load from `x` -> `int 54`;
|
||||
subtract `int 50` from `int 54` -> `int 4`;
|
||||
divide `int 12` by `int 4` -> `int 3`;
|
||||
store `int 3` to `y`;
|
||||
(note the subtract is evaluated before the divide due to the precedence
|
||||
operator)
|
||||
|
||||
[[function-call-operator]]
|
||||
==== Function Call
|
||||
|
||||
Use the `function call operator ()` to call an existing function. A
|
||||
<<painless-functions, function call>> is defined within a script.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
function_call: ID '(' ( expression (',' expression)* )? ')'';
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* A function call.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
<2> int z = add(1, 2);
|
||||
----
|
||||
+
|
||||
<1> define function `add` that returns `int` and has parameters (`int x`,
|
||||
`int y`)
|
||||
<2> declare `int z`;
|
||||
call `add` with arguments (`int 1`, `int 2`) -> `int 3`;
|
||||
store `int 3` to `z`
|
||||
|
||||
[[cast-operator]]
|
||||
==== Cast
|
||||
|
||||
An explicit cast converts the value of an original type to the equivalent value
|
||||
of a target type forcefully as an operation. Use the `cast operator '()'` to
|
||||
specify an explicit cast. Refer to <<painless-casting, casting>> for more
|
||||
information.
|
||||
|
||||
[[conditional-operator]]
|
||||
==== Conditional
|
||||
|
||||
A conditional consists of three expressions. The first expression is evaluated
|
||||
with an expected boolean result type. If the first expression evaluates to true
|
||||
then the second expression will be evaluated. If the first expression evaluates
|
||||
to false then the third expression will be evaluated. The second and third
|
||||
expressions will be <<promotion, promoted>> if the evaluated values are not the
|
||||
same type. Use the `conditional operator '? :'` as a shortcut to avoid the need
|
||||
for a full if/else branch in certain expressions.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the first expression does not evaluate to a boolean type value.
|
||||
* If the values for the second and third expressions cannot be promoted.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
conditional: expression '?' expression ':' expression;
|
||||
----
|
||||
|
||||
*Promotion*
|
||||
|
||||
[cols="<1,^1,^1,^1,^1,^1,^1,^1,^1,^1"]
|
||||
|====
|
||||
| | byte | short | char | int | long | float | double | Reference | def
|
||||
| byte | int | int | int | int | long | float | double | - | def
|
||||
| short | int | int | int | int | long | float | double | - | def
|
||||
| char | int | int | int | int | long | float | double | - | def
|
||||
| int | int | int | int | int | long | float | double | - | def
|
||||
| long | long | long | long | long | long | float | double | - | def
|
||||
| float | float | float | float | float | float | float | double | - | def
|
||||
| double | double | double | double | double | double | double | double | - | def
|
||||
| Reference | - | - | - | - | - | - | - | Object @ | def
|
||||
| def | def | def | def | def | def | def | def | def | def
|
||||
|====
|
||||
|
||||
@ If the two reference type values are the same then this promotion will not
|
||||
occur.
|
||||
|
||||
*Examples*
|
||||
|
||||
* Evaluation of conditionals.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> boolean b = true;
|
||||
<2> int x = b ? 1 : 2;
|
||||
<3> List y = x > 1 ? new ArrayList() : null;
|
||||
<4> def z = x < 2 ? x : 2.0;
|
||||
----
|
||||
+
|
||||
<1> declare `boolean b`;
|
||||
store `boolean true` to `b`
|
||||
<2> declare `int x`;
|
||||
load from `b` -> `boolean true`
|
||||
evaluate 1st expression: `int 1` -> `int 1`;
|
||||
store `int 1` to `x`
|
||||
<3> declare `List y`;
|
||||
load from `x` -> `int 1`;
|
||||
`int 1` greater than `int 1` -> `boolean false`;
|
||||
evaluate 2nd expression: `null` -> `null`;
|
||||
store `null` to `y`;
|
||||
<4> declare `def z`;
|
||||
load from `x` -> `int 1`;
|
||||
`int 1` less than `int 2` -> `boolean true`;
|
||||
evaluate 1st expression: load from `x` -> `int 1`;
|
||||
promote `int 1` and `double 2.0`: result `double`;
|
||||
implicit cast `int 1` to `double 1.0` -> `double 1.0`;
|
||||
implicit cast `double 1.0` to `def` -> `def`;
|
||||
store `def` to `z`;
|
||||
|
||||
[[assignment-operator]]
|
||||
==== Assignment
|
||||
|
||||
Use the `assignment operator '='` to store a value in a variable or reference
|
||||
type member field for use in subsequent operations. Any operation that produces
|
||||
a value can be assigned to any variable/field as long as the
|
||||
<<painless-types, types>> are the same or the resultant type can be
|
||||
<<painless-casting, implicitly cast>> to the variable/field type.
|
||||
|
||||
See <<variable-assignment, variable assignment>> for examples using variables.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the type of value is unable to match the type of variable or field.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
assignment: field '=' expression
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
The examples use the following reference type definition:
|
||||
|
||||
[source,Painless]
|
||||
----
|
||||
name:
|
||||
Example
|
||||
|
||||
non-static member fields:
|
||||
* int x
|
||||
* def y
|
||||
* List z
|
||||
----
|
||||
|
||||
* Field assignments of different type values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Example example = new Example();
|
||||
<2> example.x = 1;
|
||||
<3> example.y = 2.0;
|
||||
<4> example.z = new ArrayList();
|
||||
----
|
||||
+
|
||||
<1> declare `Example example`;
|
||||
allocate `Example` instance -> `Example reference`;
|
||||
store `Example reference` to `example`
|
||||
<2> load from `example` -> `Example reference`;
|
||||
store `int 1` to `x` of `Example reference`
|
||||
<3> load from `example` -> `Example reference`;
|
||||
implicit cast `double 2.0` to `def` -> `def`;
|
||||
store `def` to `y` of `Example reference`
|
||||
<4> load from `example` -> `Example reference`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `z` of `Example reference`
|
||||
+
|
||||
* A field assignment from a field access.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Example example = new Example();
|
||||
<2> example.x = 1;
|
||||
<3> example.y = example.x;
|
||||
----
|
||||
+
|
||||
<1> declare `Example example`;
|
||||
allocate `Example` instance -> `Example reference`;
|
||||
store `Example reference` to `example`
|
||||
<2> load from `example` -> `Example reference`;
|
||||
store `int 1` to `x` of `Example reference`
|
||||
<3> load from `example` -> `Example reference @0`;
|
||||
load from `example` -> `Example reference @1`;
|
||||
load from `x` of `Example reference @1` -> `int 1`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
store `def` to `y` of `Example reference @0`;
|
||||
(note `Example reference @0` and `Example reference @1` are the same)
|
||||
|
||||
[[compound-assignment-operator]]
|
||||
==== Compound Assignment
|
||||
|
||||
Use the `compound assignment operator '$='` as a shortcut for an assignment
|
||||
where a binary operation would occur between the variable/field as the
|
||||
left-hand side expression and a separate right-hand side expression.
|
||||
|
||||
A compound assignment is equivalent to the expression below where V is the
|
||||
variable/field and T is the type of variable/member.
|
||||
|
||||
[source,Painless]
|
||||
----
|
||||
V = (T)(V op expression);
|
||||
----
|
||||
|
||||
*Operators*
|
||||
|
||||
The table below shows the available operators for use in a compound assignment.
|
||||
Each operator follows the casting/promotion rules according to their regular
|
||||
definition. For numeric operations there is an extra implicit cast when
|
||||
necessary to return the promoted numeric type value to the original numeric type
|
||||
value of the variable/field and can result in data loss.
|
||||
|
||||
|====
|
||||
|Operator|Compound Symbol
|
||||
|Multiplication|*=
|
||||
|Division|/=
|
||||
|Remainder|%=
|
||||
|Addition|+=
|
||||
|Subtraction|-=
|
||||
|Left Shift|<<=
|
||||
|Right Shift|>>=
|
||||
|Unsigned Right Shift|>>>=
|
||||
|Bitwise And|&=
|
||||
|Boolean And|&=
|
||||
|Bitwise Xor|^=
|
||||
|Boolean Xor|^=
|
||||
|Bitwise Or|\|=
|
||||
|Boolean Or|\|=
|
||||
|String Concatenation|+=
|
||||
|====
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the type of value is unable to match the type of variable or field.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
compound_assignment: ( ID | field ) '$=' expression;
|
||||
----
|
||||
|
||||
Note the use of the `$=` represents the use of any of the possible binary
|
||||
operators.
|
||||
|
||||
*Examples*
|
||||
|
||||
* Compound assignment for each numeric operator.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int i = 10;
|
||||
<2> i *= 2;
|
||||
<3> i /= 5;
|
||||
<4> i %= 3;
|
||||
<5> i += 5;
|
||||
<6> i -= 5;
|
||||
<7> i <<= 2;
|
||||
<8> i >>= 1;
|
||||
<9> i >>>= 1;
|
||||
<10> i &= 15;
|
||||
<11> i ^= 12;
|
||||
<12> i |= 2;
|
||||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
store `int 10` to `i`
|
||||
<2> load from `i` -> `int 10`;
|
||||
multiply `int 10` and `int 2` -> `int 20`;
|
||||
store `int 20` to `i`;
|
||||
(note this is equivalent to `i = i*2`)
|
||||
<3> load from `i` -> `int 20`;
|
||||
divide `int 20` by `int 5` -> `int 4`;
|
||||
store `int 4` to `i`;
|
||||
(note this is equivalent to `i = i/5`)
|
||||
<4> load from `i` -> `int 4`;
|
||||
remainder `int 4` by `int 3` -> `int 1`;
|
||||
store `int 1` to `i`;
|
||||
(note this is equivalent to `i = i%3`)
|
||||
<5> load from `i` -> `int 1`;
|
||||
add `int 1` and `int 5` -> `int 6`;
|
||||
store `int 6` to `i`;
|
||||
(note this is equivalent to `i = i+5`)
|
||||
<6> load from `i` -> `int 6`;
|
||||
subtract `int 5` from `int 6` -> `int 1`;
|
||||
store `int 1` to `i`;
|
||||
(note this is equivalent to `i = i-5`)
|
||||
<7> load from `i` -> `int 1`;
|
||||
left shift `int 1` by `int 2` -> `int 4`;
|
||||
store `int 4` to `i`;
|
||||
(note this is equivalent to `i = i<<2`)
|
||||
<8> load from `i` -> `int 4`;
|
||||
right shift `int 4` by `int 1` -> `int 2`;
|
||||
store `int 2` to `i`;
|
||||
(note this is equivalent to `i = i>>1`)
|
||||
<9> load from `i` -> `int 2`;
|
||||
unsigned right shift `int 2` by `int 1` -> `int 1`;
|
||||
store `int 1` to `i`;
|
||||
(note this is equivalent to `i = i>>>1`)
|
||||
<10> load from `i` -> `int 1`;
|
||||
bitwise and `int 1` and `int 15` -> `int 1`;
|
||||
store `int 1` to `i`;
|
||||
(note this is equivalent to `i = i&2`)
|
||||
<11> load from `i` -> `int 1`;
|
||||
bitwise xor `int 1` and `int 12` -> `int 13`;
|
||||
store `int 13` to `i`;
|
||||
(note this is equivalent to `i = i^2`)
|
||||
<12> load from `i` -> `int 13`;
|
||||
bitwise or `int 13` and `int 2` -> `int 15`;
|
||||
store `int 15` to `i`;
|
||||
(note this is equivalent to `i = i|2`)
|
||||
+
|
||||
* Compound assignment for each boolean operator.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> boolean b = true;
|
||||
<2> b &= false;
|
||||
<3> b ^= false;
|
||||
<4> b |= true;
|
||||
----
|
||||
+
|
||||
<1> declare `boolean b`;
|
||||
store `boolean true` in `b`;
|
||||
<2> load from `b` -> `boolean true`;
|
||||
boolean and `boolean true` and `boolean false` -> `boolean false`;
|
||||
store `boolean false` to `b`;
|
||||
(note this is equivalent to `b = b && false`)
|
||||
<3> load from `b` -> `boolean false`;
|
||||
boolean xor `boolean false` and `boolean false` -> `boolean false`;
|
||||
store `boolean false` to `b`;
|
||||
(note this is equivalent to `b = b ^ false`)
|
||||
<4> load from `b` -> `boolean true`;
|
||||
boolean or `boolean false` and `boolean true` -> `boolean true`;
|
||||
store `boolean true` to `b`;
|
||||
(note this is equivalent to `b = b || true`)
|
||||
+
|
||||
* A compound assignment with the string concatenation operator.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> String s = 'compound';
|
||||
<2> s += ' assignment';
|
||||
----
|
||||
<1> declare `String s`;
|
||||
store `String 'compound'` to `s`;
|
||||
<2> load from `s` -> `String 'compound'`;
|
||||
string concat `String 'compound'` and `String ' assignment''`
|
||||
-> `String 'compound assignment'`;
|
||||
store `String 'compound assignment'` to `s`;
|
||||
(note this is equivalent to `s = s + ' assignment'`)
|
||||
+
|
||||
* A compound assignment with the `def` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> def x = 1;
|
||||
<2> x += 2;
|
||||
----
|
||||
<1> declare `def x`;
|
||||
implicit cast `int 1` to `def`;
|
||||
store `def` to `x`;
|
||||
<2> load from `x` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
add `int 1` and `int 2` -> `int 3`;
|
||||
implicit cast `int 3` to `def` -> `def`;
|
||||
store `def` to `x`;
|
||||
(note this is equivalent to `x = x+2`)
|
||||
+
|
||||
* A compound assignment with an extra implicit cast.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> byte b = 1;
|
||||
<2> b += 2;
|
||||
----
|
||||
<1> declare `byte b`;
|
||||
store `byte 1` to `x`;
|
||||
<2> load from `x` -> `byte 1`;
|
||||
implicit cast `byte 1 to `int 1` -> `int 1`;
|
||||
add `int 1` and `int 2` -> `int 3`;
|
||||
implicit cast `int 3` to `byte 3` -> `byte 3`;
|
||||
store `byte 3` to `b`;
|
||||
(note this is equivalent to `b = b+2`)
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,774 @@
|
|||
[[painless-operators-reference]]
|
||||
=== Operators: Reference
|
||||
|
||||
[[method-call-operator]]
|
||||
==== Method Call
|
||||
|
||||
Use the `method call operator '()'` to call a member method on a
|
||||
<<reference-types, reference type>> value. Implicit
|
||||
<<boxing-unboxing, boxing/unboxing>> is evaluated as necessary per argument
|
||||
during the method call. When a method call is made on a target `def` type value,
|
||||
the parameters and return type value are considered to also be of the `def` type
|
||||
and are evaluated at run-time.
|
||||
|
||||
An overloaded method is one that shares the same name with two or more methods.
|
||||
A method is overloaded based on arity where the same name is re-used for
|
||||
multiple methods as long as the number of parameters differs.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the reference type value is `null`.
|
||||
* If the member method name doesn't exist for a given reference type value.
|
||||
* If the number of arguments passed in is different from the number of specified
|
||||
parameters.
|
||||
* If the arguments cannot be implicitly cast or implicitly boxed/unboxed to the
|
||||
correct type values for the parameters.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
method_call: '.' ID arguments;
|
||||
arguments: '(' (expression (',' expression)*)? ')';
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Method calls on different reference types.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Map m = new HashMap();
|
||||
<2> m.put(1, 2);
|
||||
<3> int z = m.get(1);
|
||||
<4> def d = new ArrayList();
|
||||
<5> d.add(1);
|
||||
<6> int i = Integer.parseInt(d.get(0).toString());
|
||||
----
|
||||
+
|
||||
<1> declare `Map m`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
store `HashMap reference` to `m`
|
||||
<2> load from `m` -> `Map reference`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
implicit cast `int 2` to `def` -> `def`;
|
||||
call `put` on `Map reference` with arguments (`int 1`, `int 2`)
|
||||
<3> declare `int z`;
|
||||
load from `m` -> `Map reference`;
|
||||
call `get` on `Map reference` with arguments (`int 1`) -> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
store `int 2` to `z`
|
||||
<4> declare `def d`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList` to `def` -> `def`;
|
||||
store `def` to `d`
|
||||
<5> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`
|
||||
call `add` on `ArrayList reference` with arguments (`int 1`);
|
||||
<6> declare `int i`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`
|
||||
call `get` on `ArrayList reference` with arguments (`int 1`) -> `def`;
|
||||
implicit cast `def` to `Integer 1 reference` -> `Integer 1 reference`;
|
||||
call `toString` on `Integer 1 reference` -> `String '1'`;
|
||||
call `parseInt` on `Integer` with arguments (`String '1'`) -> `int 1`;
|
||||
store `int 1` in `i`;
|
||||
|
||||
[[field-access-operator]]
|
||||
==== Field Access
|
||||
|
||||
Use the `field access operator '.'` to store a value to or load a value from a
|
||||
<<reference-types, reference type>> member field.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the reference type value is `null`.
|
||||
* If the member field name doesn't exist for a given reference type value.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
field_access: '.' ID;
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
The examples use the following reference type definition:
|
||||
|
||||
[source,Painless]
|
||||
----
|
||||
name:
|
||||
Example
|
||||
|
||||
non-static member fields:
|
||||
* int x
|
||||
* def y
|
||||
* List z
|
||||
----
|
||||
|
||||
* Field access with the `Example` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Example example = new Example();
|
||||
<2> example.x = 1;
|
||||
<3> example.y = example.x;
|
||||
<4> example.z = new ArrayList();
|
||||
<5> example.z.add(1);
|
||||
<6> example.x = example.z.get(0);
|
||||
----
|
||||
+
|
||||
<1> declare `Example example`;
|
||||
allocate `Example` instance -> `Example reference`;
|
||||
store `Example reference` to `example`
|
||||
<2> load from `example` -> `Example reference`;
|
||||
store `int 1` to `x` of `Example reference`
|
||||
<3> load from `example` -> `Example reference @0`;
|
||||
load from `example` -> `Example reference @1`;
|
||||
load from `x` of `Example reference @1` -> `int 1`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
store `def` to `y` of `Example reference @0`;
|
||||
(note `Example reference @0` and `Example reference @1` are the same)
|
||||
<4> load from `example` -> `Example reference`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `z` of `Example reference`
|
||||
<5> load from `example` -> `Example reference`;
|
||||
load from `z` of `Example reference` -> `List reference`;
|
||||
call `add` on `List reference` with arguments (`int 1`)
|
||||
<6> load from `example` -> `Example reference @0`;
|
||||
load from `example` -> `Example reference @1`;
|
||||
load from `z` of `Example reference @1` -> `List reference`;
|
||||
call `get` on `List reference` with arguments (`int 0`) -> `int 1`;
|
||||
store `int 1` in `x` of `List reference @0`;
|
||||
(note `Example reference @0` and `Example reference @1` are the same)
|
||||
|
||||
[[null-safe-operator]]
|
||||
==== Null Safe
|
||||
|
||||
Use the `null safe operator '?.'` instead of the method call operator or field
|
||||
access operator to ensure a reference type value is `non-null` before
|
||||
a method call or field access. A `null` value will be returned if the reference
|
||||
type value is `null`, otherwise the method call or field access is evaluated.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the method call return type value or the field access type value is not
|
||||
a reference type value and is not implicitly castable to a reference type
|
||||
value.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
null_safe: null_safe_method_call
|
||||
| null_safe_field_access
|
||||
;
|
||||
|
||||
null_safe_method_call: '?.' ID arguments;
|
||||
arguments: '(' (expression (',' expression)*)? ')';
|
||||
|
||||
null_safe_field_access: '?.' ID;
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
The examples use the following reference type definition:
|
||||
|
||||
[source,Painless]
|
||||
----
|
||||
name:
|
||||
Example
|
||||
|
||||
non-static member methods:
|
||||
* List factory()
|
||||
|
||||
non-static member fields:
|
||||
* List x
|
||||
----
|
||||
|
||||
* Null safe without a `null` value.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Example example = new Example();
|
||||
<2> List x = example?.factory();
|
||||
----
|
||||
+
|
||||
<1> declare `Example example`;
|
||||
allocate `Example` instance -> `Example reference`;
|
||||
store `Example reference` to `example`
|
||||
<2> declare `List x`;
|
||||
load from `example` -> `Example reference`;
|
||||
null safe call `factory` on `Example reference` -> `List reference`;
|
||||
store `List reference` to `x`;
|
||||
+
|
||||
* Null safe with a `null` value;
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Example example = null;
|
||||
<2> List x = example?.x;
|
||||
----
|
||||
<1> declare `Example example`;
|
||||
store `null` to `example`
|
||||
<2> declare `List x`;
|
||||
load from `example` -> `Example reference`;
|
||||
null safe access `x` on `Example reference` -> `null`;
|
||||
store `null` to `x`;
|
||||
(note the *null safe operator* returned `null` because `example` is `null`)
|
||||
|
||||
[[list-initialization-operator]]
|
||||
==== List Initialization
|
||||
|
||||
Use the `list initialization operator '[]'` to allocate an `List` type instance
|
||||
to the heap with a set of pre-defined values. Each value used to initialize the
|
||||
`List` type instance is cast to a `def` type value upon insertion into the
|
||||
`List` type instance using the `add` method. The order of the specified values
|
||||
is maintained.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
list_initialization: '[' expression (',' expression)* ']'
|
||||
| '[' ']';
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* List initialization of an empty `List` type value.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> List empty = [];
|
||||
----
|
||||
+
|
||||
<1> declare `List empty`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `empty`
|
||||
+
|
||||
* List initialization with static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> List list = [1, 2, 3];
|
||||
----
|
||||
+
|
||||
<1> declare `List list`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
call `add` on `ArrayList reference` with arguments(`int 1`);
|
||||
call `add` on `ArrayList reference` with arguments(`int 2`);
|
||||
call `add` on `ArrayList reference` with arguments(`int 3`);
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `list`
|
||||
+
|
||||
* List initialization with non-static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> int i = 1;
|
||||
<2> long l = 2L;
|
||||
<3> float f = 3.0F;
|
||||
<4> double d = 4.0;
|
||||
<5> String s = "5";
|
||||
<6> List list = [i, l, f*d, s];
|
||||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
store `int 1` to `i`
|
||||
<2> declare `long l`;
|
||||
store `long 2` to `l`
|
||||
<3> declare `float f`;
|
||||
store `float 3.0` to `f`
|
||||
<4> declare `double d`;
|
||||
store `double 4.0` to `d`
|
||||
<5> declare `String s`;
|
||||
store `String "5"` to `s`
|
||||
<6> declare `List list`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
load from `i` -> `int 1`;
|
||||
call `add` on `ArrayList reference` with arguments(`int 1`);
|
||||
load from `l` -> `long 2`;
|
||||
call `add` on `ArrayList reference` with arguments(`long 2`);
|
||||
load from `f` -> `float 3.0`;
|
||||
load from `d` -> `double 4.0`;
|
||||
promote `float 3.0` and `double 4.0`: result `double`;
|
||||
implicit cast `float 3.0` to `double 3.0` -> `double 3.0`;
|
||||
multiply `double 3.0` and `double 4.0` -> `double 12.0`;
|
||||
call `add` on `ArrayList reference` with arguments(`double 12.0`);
|
||||
load from `s` -> `String "5"`;
|
||||
call `add` on `ArrayList reference` with arguments(`String "5"`);
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `list`
|
||||
|
||||
[[list-access-operator]]
|
||||
==== List Access
|
||||
|
||||
Use the `list access operator '[]'` as a shortcut for a `set` method call or
|
||||
`get` method call made on a `List` type value.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a value other than a `List` type value is accessed.
|
||||
* If a non-integer type value is used as an index for a `set` method call or
|
||||
`get` method call.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
list_access: '[' expression ']'
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* List access with the `List` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> List list = new ArrayList();
|
||||
<2> list.add(1);
|
||||
<3> list.add(2);
|
||||
<4> list.add(3);
|
||||
<5> list[0] = 2;
|
||||
<6> list[1] = 5;
|
||||
<7> int x = list[0] + list[1];
|
||||
<8> int y = 1;
|
||||
<9> int z = list[y];
|
||||
----
|
||||
+
|
||||
<1> declare `List list`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `list`
|
||||
<2> load from `list` -> `List reference`;
|
||||
call `add` on `List reference` with arguments(`int 1`)
|
||||
<3> load from `list` -> `List reference`;
|
||||
call `add` on `List reference` with arguments(`int 2`)
|
||||
<4> load from `list` -> `List reference`;
|
||||
call `add` on `List reference` with arguments(`int 3`)
|
||||
<5> load from `list` -> `List reference`;
|
||||
call `set` on `List reference` with arguments(`int 0`, `int 2`)
|
||||
<6> load from `list` -> `List reference`;
|
||||
call `set` on `List reference` with arguments(`int 1`, `int 5`)
|
||||
<7> declare `int x`;
|
||||
load from `list` -> `List reference`;
|
||||
call `get` on `List reference` with arguments(`int 0`) -> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
load from `list` -> `List reference`;
|
||||
call `get` on `List reference` with arguments(`int 1`) -> `def`;
|
||||
implicit cast `def` to `int 5` -> `int 5`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
store `int 7` to `x`
|
||||
<8> declare `int y`;
|
||||
store `int 1` int `y`
|
||||
<9> declare `int z`;
|
||||
load from `list` -> `List reference`;
|
||||
load from `y` -> `int 1`;
|
||||
call `get` on `List reference` with arguments(`int 1`) -> `def`;
|
||||
implicit cast `def` to `int 5` -> `int 5`;
|
||||
store `int 5` to `z`
|
||||
+
|
||||
* List access with the `def` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> def d = new ArrayList();
|
||||
<2> d.add(1);
|
||||
<3> d.add(2);
|
||||
<4> d.add(3);
|
||||
<5> d[0] = 2;
|
||||
<6> d[1] = 5;
|
||||
<7> def x = d[0] + d[1];
|
||||
<8> def y = 1;
|
||||
<9> def z = d[y];
|
||||
----
|
||||
+
|
||||
<1> declare `List d`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `def` -> `def`;
|
||||
store `def` to `d`
|
||||
<2> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `add` on `ArrayList reference` with arguments(`int 1`)
|
||||
<3> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `add` on `ArrayList reference` with arguments(`int 2`)
|
||||
<4> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `add` on `ArrayList reference` with arguments(`int 3`)
|
||||
<5> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `set` on `ArrayList reference` with arguments(`int 0`, `int 2`)
|
||||
<6> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `set` on `ArrayList reference` with arguments(`int 1`, `int 5`)
|
||||
<7> declare `def x`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `get` on `ArrayList reference` with arguments(`int 0`) -> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `get` on `ArrayList reference` with arguments(`int 1`) -> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
store `int 7` to `x`
|
||||
<8> declare `int y`;
|
||||
store `int 1` int `y`
|
||||
<9> declare `int z`;
|
||||
load from `d` -> `ArrayList reference`;
|
||||
load from `y` -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
call `get` on `ArrayList reference` with arguments(`int 1`) -> `def`;
|
||||
store `def` to `z`
|
||||
|
||||
[[map-initialization-operator]]
|
||||
==== Map Initialization
|
||||
|
||||
Use the `map initialization operator '[:]'` to allocate a `Map` type instance to
|
||||
the heap with a set of pre-defined values. Each pair of values used to
|
||||
initialize the `Map` type instance are cast to `def` type values upon insertion
|
||||
into the `Map` type instance using the `put` method.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
map_initialization: '[' key_pair (',' key_pair)* ']'
|
||||
| '[' ':' ']';
|
||||
key_pair: expression ':' expression
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Map initialization of an empty `Map` type value.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Map empty = [:];
|
||||
----
|
||||
+
|
||||
<1> declare `Map empty`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
store `Map reference` to `empty`
|
||||
+
|
||||
* Map initialization with static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Map map = [1:2, 3:4, 5:6];
|
||||
----
|
||||
+
|
||||
<1> declare `Map map`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
call `put` on `HashMap reference` with arguments(`int 1`, `int 2`);
|
||||
call `put` on `HashMap reference` with arguments(`int 3`, `int 4`);
|
||||
call `put` on `HashMap reference` with arguments(`int 5`, `int 6`);
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
store `Map reference` to `map`
|
||||
+
|
||||
* Map initialization with non-static values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> byte b = 0;
|
||||
<2> int i = 1;
|
||||
<3> long l = 2L;
|
||||
<4> float f = 3.0F;
|
||||
<5> double d = 4.0;
|
||||
<6> String s = "5";
|
||||
<7> Map map = [b:i, l:f*d, d:s];
|
||||
----
|
||||
+
|
||||
<1> declare `byte b`;
|
||||
store `byte 0` to `b`
|
||||
<2> declare `int i`;
|
||||
store `int 1` to `i`
|
||||
<3> declare `long l`;
|
||||
store `long 2` to `l`
|
||||
<4> declare `float f`;
|
||||
store `float 3.0` to `f`
|
||||
<5> declare `double d`;
|
||||
store `double 4.0` to `d`
|
||||
<6> declare `String s`;
|
||||
store `String "5"` to `s`
|
||||
<7> declare `Map map`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
load from `b` -> `byte 0`;
|
||||
load from `i` -> `int 1`;
|
||||
call `put` on `HashMap reference` with arguments(`byte 0`, `int 1`);
|
||||
load from `l` -> `long 2`;
|
||||
load from `f` -> `float 3.0`;
|
||||
load from `d` -> `double 4.0`;
|
||||
promote `float 3.0` and `double 4.0`: result `double`;
|
||||
implicit cast `float 3.0` to `double 3.0` -> `double 3.0`;
|
||||
multiply `double 3.0` and `double 4.0` -> `double 12.0`;
|
||||
call `put` on `HashMap reference` with arguments(`long 2`, `double 12.0`);
|
||||
load from `d` -> `double 4.0`;
|
||||
load from `s` -> `String "5"`;
|
||||
call `put` on `HashMap reference` with
|
||||
arguments(`double 4.0`, `String "5"`);
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
store `Map reference` to `map`
|
||||
|
||||
[[map-access-operator]]
|
||||
==== Map Access
|
||||
|
||||
Use the `map access operator '[]'` as a shortcut for a `put` method call or
|
||||
`get` method call made on a `Map` type value.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a value other than a `Map` type value is accessed.
|
||||
|
||||
*Grammar*
|
||||
[source,ANTLR4]
|
||||
----
|
||||
map_access: '[' expression ']'
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Map access with the `Map` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Map map = new HashMap();
|
||||
<2> map['value2'] = 2;
|
||||
<3> map['value5'] = 5;
|
||||
<4> int x = map['value2'] + map['value5'];
|
||||
<5> String y = 'value5';
|
||||
<6> int z = x[z];
|
||||
----
|
||||
+
|
||||
<1> declare `Map map`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
store `Map reference` to `map`
|
||||
<2> load from `map` -> `Map reference`;
|
||||
call `put` on `Map reference` with arguments(`String 'value2'`, `int 2`)
|
||||
<3> load from `map` -> `Map reference`;
|
||||
call `put` on `Map reference` with arguments(`String 'value5'`, `int 5`)
|
||||
<4> declare `int x`;
|
||||
load from `map` -> `Map reference`;
|
||||
call `get` on `Map reference` with arguments(`String 'value2'`) -> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
load from `map` -> `Map reference`;
|
||||
call `get` on `Map reference` with arguments(`String 'value5'`) -> `def`;
|
||||
implicit cast `def` to `int 5` -> `int 5`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
store `int 7` to `x`
|
||||
<5> declare `String y`;
|
||||
store `String 'value5'` to `y`
|
||||
<6> declare `int z`;
|
||||
load from `map` -> `Map reference`;
|
||||
load from `y` -> `String 'value5'`;
|
||||
call `get` on `Map reference` with arguments(`String 'value5'`) -> `def`;
|
||||
implicit cast `def` to `int 5` -> `int 5`;
|
||||
store `int 5` to `z`
|
||||
+
|
||||
* Map access with the `def` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> def d = new HashMap();
|
||||
<2> d['value2'] = 2;
|
||||
<3> d['value5'] = 5;
|
||||
<4> int x = d['value2'] + d['value5'];
|
||||
<5> String y = 'value5';
|
||||
<6> def z = d[y];
|
||||
----
|
||||
+
|
||||
<1> declare `def d`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `def` -> `def`;
|
||||
store `def` to `d`
|
||||
<2> load from `d` -> `def`;
|
||||
implicit cast `def` to `HashMap reference` -> `HashMap reference`;
|
||||
call `put` on `HashMap reference` with arguments(`String 'value2'`, `int 2`)
|
||||
<3> load from `d` -> `def`;
|
||||
implicit cast `def` to `HashMap reference` -> `HashMap reference`;
|
||||
call `put` on `HashMap reference` with arguments(`String 'value5'`, `int 5`)
|
||||
<4> declare `int x`;
|
||||
load from `d` -> `def`;
|
||||
implicit cast `def` to `HashMap reference` -> `HashMap reference`;
|
||||
call `get` on `HashMap reference` with arguments(`String 'value2'`)
|
||||
-> `def`;
|
||||
implicit cast `def` to `int 2` -> `int 2`;
|
||||
load from `d` -> `def`;
|
||||
call `get` on `HashMap reference` with arguments(`String 'value5'`)
|
||||
-> `def`;
|
||||
implicit cast `def` to `int 5` -> `int 5`;
|
||||
add `int 2` and `int 5` -> `int 7`;
|
||||
store `int 7` to `x`
|
||||
<5> declare `String y`;
|
||||
store `String 'value5'` to `y`
|
||||
<6> declare `def z`;
|
||||
load from `d` -> `def`;
|
||||
load from `y` -> `String 'value5'`;
|
||||
call `get` on `HashMap reference` with arguments(`String 'value5'`)
|
||||
-> `def`;
|
||||
store `def` to `z`
|
||||
|
||||
[[new-instance-operator]]
|
||||
==== New Instance
|
||||
|
||||
Use the `new instance operator 'new ()'` to allocate a
|
||||
<<reference-types, reference type>> instance to the heap and call a specified
|
||||
constructor. Implicit <<boxing-unboxing, boxing/unboxing>> is evaluated as
|
||||
necessary per argument during the constructor call.
|
||||
|
||||
An overloaded constructor is one that shares the same name with two or more
|
||||
constructors. A constructor is overloaded based on arity where the same
|
||||
reference type name is re-used for multiple constructors as long as the number
|
||||
of parameters differs.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the reference type name doesn't exist for instance allocation.
|
||||
* If the number of arguments passed in is different from the number of specified
|
||||
parameters.
|
||||
* If the arguments cannot be implicitly cast or implicitly boxed/unboxed to the
|
||||
correct type values for the parameters.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
new_instance: 'new' TYPE '(' (expression (',' expression)*)? ')';
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Allocation of new instances with different types.
|
||||
|
||||
[source,Painless]
|
||||
----
|
||||
<1> Map m = new HashMap();
|
||||
<2> def d = new ArrayList();
|
||||
<3> def e = new HashMap(m);
|
||||
----
|
||||
<1> declare `Map m`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
store `Map reference` to `m`;
|
||||
<2> declare `def d`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `def` -> `def`;
|
||||
store `def` to `d`;
|
||||
<3> declare `def e`;
|
||||
load from `m` -> `Map reference`;
|
||||
allocate `HashMap` instance with arguments (`Map reference`)
|
||||
-> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `def` -> `def`;
|
||||
store `def` to `e`;
|
||||
|
||||
[[string-concatenation-operator]]
|
||||
==== String Concatenation
|
||||
|
||||
Use the `string concatenation operator '+'` to concatenate two values together
|
||||
where at least one of the values is a <<string-type, `String` type>>.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
concatenate: expression '+' expression;
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* String concatenation with different primitive types.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> String x = "con";
|
||||
<2> String y = x + "cat";
|
||||
<3> String z = 4 + 5 + x;
|
||||
----
|
||||
+
|
||||
<1> declare `String x`;
|
||||
store `String "con"` to `x`;
|
||||
<2> declare `String y`;
|
||||
load from `x` -> `String "con"`;
|
||||
concat `String "con"` and `String "cat"` -> `String "concat"`;
|
||||
store `String "concat"` to `y`
|
||||
<3> declare `String z`;
|
||||
add `int 4` and `int 5` -> `int 9`;
|
||||
concat `int 9` and `String "9concat"`;
|
||||
store `String "9concat"` to `z`;
|
||||
(note the addition is done prior to the concatenation due to precedence and
|
||||
associativity of the specific operations)
|
||||
+
|
||||
* String concatenation with the `def` type.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> def d = 2;
|
||||
<2> d = "con" + d + "cat";
|
||||
----
|
||||
+
|
||||
<1> declare `def`;
|
||||
implicit cast `int 2` to `def` -> `def`;
|
||||
store `def` in `d`;
|
||||
<2> concat `String "con"` and `int 9` -> `String "con9"`;
|
||||
concat `String "con9"` and `String "con"` -> `String "con9cat"`
|
||||
implicit cast `String "con9cat"` to `def` -> `def`;
|
||||
store `def` to `d`;
|
||||
(note the switch in type of `d` from `int` to `String`)
|
||||
|
||||
[[elvis-operator]]
|
||||
==== Elvis
|
||||
|
||||
An elvis consists of two expressions. The first expression is evaluated
|
||||
with to check for a `null` value. If the first expression evaluates to
|
||||
`null` then the second expression is evaluated and its value used. If the first
|
||||
expression evaluates to `non-null` then the resultant value of the first
|
||||
expression is used. Use the `elvis operator '?:'` as a shortcut for the
|
||||
conditional operator.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the first expression or second expression cannot produce a `null` value.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
elvis: expression '?:' expression;
|
||||
----
|
||||
|
||||
*Examples*
|
||||
|
||||
* Elvis with different reference types.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
<1> List x = new ArrayList();
|
||||
<2> List y = x ?: new ArrayList();
|
||||
<3> y = null;
|
||||
<4> List z = y ?: new ArrayList();
|
||||
----
|
||||
+
|
||||
<1> declare `List x`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `x`;
|
||||
<2> declare `List y`;
|
||||
load `x` -> `List reference`;
|
||||
`List reference` equals `null` -> `false`;
|
||||
evaluate 1st expression: `List reference` -> `List reference`;
|
||||
store `List reference` to `y`
|
||||
<3> store `null` to `y`;
|
||||
<4> declare `List z`;
|
||||
load `y` -> `List reference`;
|
||||
`List reference` equals `null` -> `true`;
|
||||
evaluate 2nd expression:
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
store `List reference` to `z`;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,33 @@
|
|||
[[painless-regexes]]
|
||||
=== Regexes
|
||||
|
||||
Regular expression constants are directly supported. To ensure fast performance,
|
||||
this is the only mechanism for creating patterns. Regular expressions
|
||||
are always constants and compiled efficiently a single time.
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
Pattern p = /[aeiou]/
|
||||
---------------------------------------------------------
|
||||
|
||||
[[pattern-flags]]
|
||||
==== Pattern flags
|
||||
|
||||
You can define flags on patterns in Painless by adding characters after the
|
||||
trailing `/` like `/foo/i` or `/foo \w #comment/iUx`. Painless exposes all of
|
||||
the flags from Java's
|
||||
https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html[
|
||||
Pattern class] using these characters:
|
||||
|
||||
[cols="<,<,<",options="header",]
|
||||
|=======================================================================
|
||||
| Character | Java Constant | Example
|
||||
|`c` | CANON_EQ | `'å' ==~ /å/c` (open in hex editor to see)
|
||||
|`i` | CASE_INSENSITIVE | `'A' ==~ /a/i`
|
||||
|`l` | LITERAL | `'[a]' ==~ /[a]/l`
|
||||
|`m` | MULTILINE | `'a\nb\nc' =~ /^b$/m`
|
||||
|`s` | DOTALL (aka single line) | `'a\nb\nc' =~ /.b./s`
|
||||
|`U` | UNICODE_CHARACTER_CLASS | `'Ɛ' ==~ /\\w/U`
|
||||
|`u` | UNICODE_CASE | `'Ɛ' ==~ /ɛ/iu`
|
||||
|`x` | COMMENTS (aka extended) | `'a' ==~ /a #comment/x`
|
||||
|=======================================================================
|
|
@ -0,0 +1,6 @@
|
|||
[[painless-scripts]]
|
||||
=== Scripts
|
||||
|
||||
Scripts are composed of one-to-many <<painless-statements, statements>> and are
|
||||
run in a sandbox that determines what local variables are immediately available
|
||||
along with what APIs are whitelisted for use.
|
|
@ -0,0 +1,14 @@
|
|||
[[painless-statements]]
|
||||
=== Statements
|
||||
|
||||
Painless supports all of Java's https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html[
|
||||
control flow statements] except the `switch` statement.
|
||||
|
||||
Painless also supports the `for in` syntax from Groovy:
|
||||
|
||||
[source,painless]
|
||||
---------------------------------------------------------
|
||||
for (item : list) {
|
||||
...
|
||||
}
|
||||
---------------------------------------------------------
|
|
@ -12,16 +12,16 @@ belongs to one of the following categories: <<primitive-types, primitive>>,
|
|||
|
||||
A primitive type represents basic data built natively into the JVM and is
|
||||
allocated to non-heap memory. Declare a primitive type
|
||||
<<painless-variables, variable>>, and assign it a primitive type value for
|
||||
evaluation during later operations. The default value for a newly-declared
|
||||
primitive type variable is listed as part of the definitions below. A primitive
|
||||
type value is copied during an assignment or as an argument for a
|
||||
method/function call.
|
||||
<<painless-variables, variable>> or access a primitive type member field (from
|
||||
a reference type instance), and assign it a primitive type value for evaluation
|
||||
during later operations. The default value for a newly-declared primitive type
|
||||
variable is listed as part of the definitions below. A primitive type value is
|
||||
copied during an assignment or as an argument for a method/function call.
|
||||
|
||||
A primitive type has a corresponding reference type (also known as a boxed
|
||||
type). Use the <<field-access, field access operator>> or
|
||||
<<method-access, method call operator>> on a primitive type value to force
|
||||
evaluation as its corresponding reference type value.
|
||||
type). Use the <<field-access-operator, field access operator>> or
|
||||
<<method-call-operator, method call operator>> on a primitive type value to
|
||||
force evaluation as its corresponding reference type value.
|
||||
|
||||
The following primitive types are available:
|
||||
|
||||
|
@ -83,11 +83,11 @@ logical quantity with two possible values of `true` and `false`
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
assign `int 1` to `i`
|
||||
store `int 1` to `i`
|
||||
<2> declare `double d`;
|
||||
assign default `double 0.0` to `d`
|
||||
store default `double 0.0` to `d`
|
||||
<3> declare `boolean b`;
|
||||
assign `boolean true` to `b`
|
||||
store `boolean true` to `b`
|
||||
+
|
||||
* Method call on a primitive type using the corresponding reference type.
|
||||
+
|
||||
|
@ -98,8 +98,8 @@ logical quantity with two possible values of `true` and `false`
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
assign `int 1` to `i`
|
||||
<2> access `i` -> `int 1`;
|
||||
store `int 1` to `i`
|
||||
<2> load from `i` -> `int 1`;
|
||||
box `int 1` -> `Integer 1 reference`;
|
||||
call `toString` on `Integer 1 reference` -> `String '1'`
|
||||
|
||||
|
@ -113,7 +113,7 @@ multiple pieces of data (member fields) and logic to manipulate that data
|
|||
|
||||
A reference type instance is a single set of data for one reference type
|
||||
object allocated to the heap. Use the
|
||||
<<constructor-call, new instance operator>> to allocate a reference type
|
||||
<<new-instance-operator, new instance operator>> to allocate a reference type
|
||||
instance. Use a reference type instance to load from, store to, and manipulate
|
||||
complex data.
|
||||
|
||||
|
@ -122,10 +122,11 @@ reference type values may refer to the same reference type instance. A change to
|
|||
a reference type instance will affect all reference type values referring to
|
||||
that specific instance.
|
||||
|
||||
Declare a reference type <<painless-variables, variable>>, and assign it a
|
||||
reference type value for evaluation during later operations. The default value
|
||||
for a newly-declared reference type variable is `null`. A reference type value
|
||||
is shallow-copied during an assignment or as an argument for a method/function
|
||||
Declare a reference type <<painless-variables, variable>> or access a reference
|
||||
type member field (from a reference type instance), and assign it a reference
|
||||
type value for evaluation during later operations. The default value for a
|
||||
newly-declared reference type variable is `null`. A reference type value is
|
||||
shallow-copied during an assignment or as an argument for a method/function
|
||||
call. Assign `null` to a reference type variable to indicate the reference type
|
||||
value refers to no reference type instance. The JVM will garbage collect a
|
||||
reference type instance when it is no longer referred to by any reference type
|
||||
|
@ -138,8 +139,8 @@ static member field::
|
|||
|
||||
A static member field is a named and typed piece of data. Each reference type
|
||||
*object* contains one set of data representative of its static member fields.
|
||||
Use the <<field-access, field access operator>> in correspondence with the
|
||||
reference type object name to access a static member field for loading and
|
||||
Use the <<field-access-operator, field access operator>> in correspondence with
|
||||
the reference type object name to access a static member field for loading and
|
||||
storing to a specific reference type *object*. No reference type instance
|
||||
allocation is necessary to use a static member field.
|
||||
|
||||
|
@ -148,32 +149,34 @@ non-static member field::
|
|||
A non-static member field is a named and typed piece of data. Each reference
|
||||
type *instance* contains one set of data representative of its reference type
|
||||
object's non-static member fields. Use the
|
||||
<<field-access, field access operator>> for loading and storing to a non-static
|
||||
member field of a specific reference type *instance*. An allocated reference
|
||||
type instance is required to use a non-static member field.
|
||||
<<field-access-operator, field access operator>> for loading and storing to a
|
||||
non-static member field of a specific reference type *instance*. An allocated
|
||||
reference type instance is required to use a non-static member field.
|
||||
|
||||
static member method::
|
||||
|
||||
A static member method is a function called on a reference type *object*. Use
|
||||
the <<method-access, method call operator>> in correspondence with the reference
|
||||
type object name to call a static member method. No reference type instance
|
||||
allocation is necessary to use a static member method.
|
||||
A static member method is a <<painless-functions, function>> called on a
|
||||
reference type *object*. Use the <<method-call-operator, method call operator>>
|
||||
in correspondence with the reference type object name to call a static member
|
||||
method. No reference type instance allocation is necessary to use a static
|
||||
member method.
|
||||
|
||||
non-static member method::
|
||||
|
||||
A non-static member method is a function called on a reference type *instance*.
|
||||
A non-static member method called on a reference type instance can load from and
|
||||
store to non-static member fields of that specific reference type instance. Use
|
||||
the <<method-access, method call operator>> in correspondence with a specific
|
||||
reference type instance to call a non-static member method. An allocated
|
||||
reference type instance is required to use a non-static member method.
|
||||
A non-static member method is a <<painless-functions, function>> called on a
|
||||
reference type *instance*. A non-static member method called on a reference type
|
||||
instance can load from and store to non-static member fields of that specific
|
||||
reference type instance. Use the <<method-call-operator, method call operator>>
|
||||
in correspondence with a specific reference type instance to call a non-static
|
||||
member method. An allocated reference type instance is required to use a
|
||||
non-static member method.
|
||||
|
||||
constructor::
|
||||
|
||||
A constructor is a special type of function used to allocate a reference type
|
||||
*instance* defined by a specific reference type *object*. Use the
|
||||
<<constructor-call, new instance operator>> to allocate a reference type
|
||||
instance.
|
||||
A constructor is a special type of <<painless-functions, function>> used to
|
||||
allocate a reference type *instance* defined by a specific reference type
|
||||
*object*. Use the <<new-instance-operator, new instance operator>> to allocate
|
||||
a reference type instance.
|
||||
|
||||
A reference type object follows a basic inheritance model. Consider types A and
|
||||
B. Type A is considered to be a parent of B, and B a child of A, if B inherits
|
||||
|
@ -198,16 +201,16 @@ relationships.
|
|||
<1> declare `List l`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `l`
|
||||
<2> access `l` -> `List reference`;
|
||||
store `List reference` to `l`
|
||||
<2> load from `l` -> `List reference`;
|
||||
implicit cast `int 1` to `def` -> `def`
|
||||
call `add` on `List reference` with arguments (`def`)
|
||||
<3> declare `int i`;
|
||||
access `l` -> `List reference`;
|
||||
load from `l` -> `List reference`;
|
||||
call `get` on `List reference` with arguments (`int 0`) -> `def`;
|
||||
implicit cast `def` to `int 1` -> `int 1`;
|
||||
add `int 1` and `int 2` -> `int 3`;
|
||||
assign `int 3` to `i`
|
||||
store `int 3` to `i`
|
||||
+
|
||||
* Sharing a reference type instance.
|
||||
+
|
||||
|
@ -223,26 +226,26 @@ relationships.
|
|||
<1> declare `List l0`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `l0`
|
||||
store `List reference` to `l0`
|
||||
<2> declare `List l1`;
|
||||
access `l0` -> `List reference`;
|
||||
assign `List reference` to `l1`
|
||||
load from `l0` -> `List reference`;
|
||||
store `List reference` to `l1`
|
||||
(note `l0` and `l1` refer to the same instance known as a shallow-copy)
|
||||
<3> access `l0` -> `List reference`;
|
||||
<3> load from `l0` -> `List reference`;
|
||||
implicit cast `int 1` to `def` -> `def`
|
||||
call `add` on `List reference` with arguments (`def`)
|
||||
<4> access `l1` -> `List reference`;
|
||||
<4> load from `l1` -> `List reference`;
|
||||
implicit cast `int 2` to `def` -> `def`
|
||||
call `add` on `List reference` with arguments (`def`)
|
||||
<5> declare `int i`;
|
||||
access `l0` -> `List reference`;
|
||||
load from `l0` -> `List reference`;
|
||||
call `get` on `List reference` with arguments (`int 0`) -> `def @0`;
|
||||
implicit cast `def @0` to `int 1` -> `int 1`;
|
||||
access `l1` -> `List reference`;
|
||||
load from `l1` -> `List reference`;
|
||||
call `get` on `List reference` with arguments (`int 1`) -> `def @1`;
|
||||
implicit cast `def @1` to `int 2` -> `int 2`;
|
||||
add `int 1` and `int 2` -> `int 3`;
|
||||
assign `int 3` to `i`;
|
||||
store `int 3` to `i`;
|
||||
+
|
||||
* Using the static members of a reference type.
|
||||
+
|
||||
|
@ -253,11 +256,11 @@ relationships.
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
access `MAX_VALUE` on `Integer` -> `int 2147483647`;
|
||||
assign `int 2147483647` to `i`
|
||||
load from `MAX_VALUE` on `Integer` -> `int 2147483647`;
|
||||
store `int 2147483647` to `i`
|
||||
<2> declare `long l`;
|
||||
call `parseLong` on `Long` with arguments (`long 123`) -> `long 123`;
|
||||
assign `long 123` to `l`
|
||||
store `long 123` to `l`
|
||||
|
||||
[[dynamic-types]]
|
||||
==== Dynamic Types
|
||||
|
@ -268,11 +271,12 @@ the behavior of whatever value it represents at run-time and will always
|
|||
represent the child-most descendant type value of any type value when evaluated
|
||||
during operations.
|
||||
|
||||
Declare a `def` type <<painless-variables, variable>>, and assign it
|
||||
any type of value for evaluation during later operations. The default value
|
||||
for a newly-declared `def` type variable is `null`. A `def` type variable or
|
||||
method/function parameter can change the type it represents during the
|
||||
compilation and evaluation of a script.
|
||||
Declare a `def` type <<painless-variables, variable>> or access a `def` type
|
||||
member field (from a reference type instance), and assign it any type of value
|
||||
for evaluation during later operations. The default value for a newly-declared
|
||||
`def` type variable is `null`. A `def` type variable or method/function
|
||||
parameter can change the type it represents during the compilation and
|
||||
evaluation of a script.
|
||||
|
||||
Using the `def` type can have a slight impact on performance. Use only primitive
|
||||
types and reference types directly when performance is critical.
|
||||
|
@ -295,13 +299,13 @@ types and reference types directly when performance is critical.
|
|||
+
|
||||
<1> declare `def dp`;
|
||||
implicit cast `int 1` to `def` -> `def`;
|
||||
assign `def` to `dp`
|
||||
store `def` to `dp`
|
||||
<2> declare `def dr`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `def` -> `def`;
|
||||
assign `def` to `dr`
|
||||
<3> access `dp` -> `def`;
|
||||
assign `def` to `dr`;
|
||||
store `def` to `dr`
|
||||
<3> load from `dp` -> `def`;
|
||||
store `def` to `dr`;
|
||||
(note the switch in the type `dr` represents from `ArrayList` to `int`)
|
||||
+
|
||||
* A `def` type value representing the child-most descendant of a value.
|
||||
|
@ -317,12 +321,12 @@ types and reference types directly when performance is critical.
|
|||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `Object reference`
|
||||
-> `Object reference`;
|
||||
assign `Object reference` to `l`
|
||||
store `Object reference` to `l`
|
||||
<2> declare `def d`;
|
||||
access `l` -> `Object reference`;
|
||||
load from `l` -> `Object reference`;
|
||||
implicit cast `Object reference` to `def` -> `def`;
|
||||
assign `def` to `d`;
|
||||
<3> access `d` -> `def`;
|
||||
store `def` to `d`;
|
||||
<3> load from `d` -> `def`;
|
||||
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
|
||||
call `ensureCapacity` on `ArrayList reference` with arguments (`int 10`);
|
||||
(note `def` was implicit cast to `ArrayList reference`
|
||||
|
@ -333,9 +337,9 @@ types and reference types directly when performance is critical.
|
|||
==== String Type
|
||||
|
||||
The `String` type is a specialized reference type that does not require
|
||||
explicit allocation. Use a <<strings, string literal>> to directly evaluate a
|
||||
`String` type value. While not required, the
|
||||
<<constructor-call, new instance operator>> can allocate `String` type
|
||||
explicit allocation. Use a <<string-literals, string literal>> to directly
|
||||
evaluate a `String` type value. While not required, the
|
||||
<<new-instance-operator, new instance operator>> can allocate `String` type
|
||||
instances.
|
||||
|
||||
*Examples*
|
||||
|
@ -351,15 +355,15 @@ instances.
|
|||
----
|
||||
+
|
||||
<1> declare `String r`;
|
||||
assign `String "some text"` to `r`
|
||||
store `String "some text"` to `r`
|
||||
<2> declare `String s`;
|
||||
assign `String 'some text'` to `s`
|
||||
store `String 'some text'` to `s`
|
||||
<3> declare `String t`;
|
||||
allocate `String` instance with arguments (`String "some text"`)
|
||||
-> `String "some text"`;
|
||||
assign `String "some text"` to `t`
|
||||
store `String "some text"` to `t`
|
||||
<4> declare `String u`;
|
||||
assign default `null` to `u`
|
||||
store default `null` to `u`
|
||||
|
||||
[[void-type]]
|
||||
==== void Type
|
||||
|
@ -382,35 +386,38 @@ void addToList(List l, def d) {
|
|||
==== Array Type
|
||||
|
||||
An array type is a specialized reference type where an array type instance
|
||||
represents a series of values allocated to the heap. All values in an array
|
||||
type instance are of the same type. Each value is assigned an index from within
|
||||
the range `[0, length)` where length is the total number of values allocated for
|
||||
the array type instance.
|
||||
contains a series of values allocated to the heap. Each value in an array type
|
||||
instance is defined as an element. All elements in an array type instance are of
|
||||
the same type (element type) specified as part of declaration. Each element is
|
||||
assigned an index within the range `[0, length)` where length is the total
|
||||
number of elements allocated for an array type instance.
|
||||
|
||||
Use the <<new-array, new array operator>> or the
|
||||
<<array-initialization, array initialization operator>> to allocate an array
|
||||
type instance. Declare an array type <<painless-variables, variable>>, and
|
||||
assign it an array type value for evaluation during later operations. The
|
||||
default value for a newly-declared array type variable is `null`. An array type
|
||||
value is shallow-copied during an assignment or as an argument for a
|
||||
method/function call. Assign `null` to an array type variable to indicate the
|
||||
array type value refers to no array type instance. The JVM will garbage collect
|
||||
an array type instance when it is no longer referred to by any array type
|
||||
values. Pass `null` as an argument to a method/function call to indicate the
|
||||
argument refers to no array type instance.
|
||||
Use the <<new-array-operator, new array operator>> or the
|
||||
<<array-initialization-operator, array initialization operator>> to allocate an
|
||||
array type instance. Declare an array type <<painless-variables, variable>> or
|
||||
access an array type member field (from a reference type instance), and assign
|
||||
it an array type value for evaluation during later operations. The default value
|
||||
for a newly-declared array type variable is `null`. An array type value is
|
||||
shallow-copied during an assignment or as an argument for a method/function
|
||||
call. Assign `null` to an array type variable to indicate the array type value
|
||||
refers to no array type instance. The JVM will garbage collect an array type
|
||||
instance when it is no longer referred to by any array type values. Pass `null`
|
||||
as an argument to a method/function call to indicate the argument refers to no
|
||||
array type instance.
|
||||
|
||||
Use the <<array-length, array length operator>> to retrieve the length of an
|
||||
array type value as an int type value. Use the
|
||||
<<array-access, array access operator>> to load from and store to individual
|
||||
values within an array type value.
|
||||
Use the <<array-length-operator, array length operator>> to retrieve the length
|
||||
of an array type value as an `int` type value. Use the
|
||||
<<array-access-operator, array access operator>> to load from and store to
|
||||
an individual element within an array type instance.
|
||||
|
||||
When an array type instance is allocated with multiple dimensions using the
|
||||
range `[2, d]` where `d >= 2`, each dimension in the range `[1, d-1]` is also
|
||||
an array type. The array type of each dimension, `n`, is an array type with the
|
||||
number of dimensions equal to `d-n`. For example, consider `int[][][]` with 3
|
||||
dimensions. The 3rd dimension, `d-3`, is the primitive type `int`. The 2nd
|
||||
dimension, `d-2`, is the array type `int[]`. And the 1st dimension, `d-1` is
|
||||
the array type `int[][]`.
|
||||
range `[2, d]` where `d >= 2`, each element within each dimension in the range
|
||||
`[1, d-1]` is also an array type. The element type of each dimension, `n`, is an
|
||||
array type with the number of dimensions equal to `d-n`. For example, consider
|
||||
`int[][][]` with 3 dimensions. Each element in the 3rd dimension, `d-3`, is the
|
||||
primitive type `int`. Each element in the 2nd dimension, `d-2`, is the array
|
||||
type `int[]`. And each element in the 1st dimension, `d-1` is the array type
|
||||
`int[][]`.
|
||||
|
||||
*Examples*
|
||||
|
||||
|
@ -426,26 +433,26 @@ the array type `int[][]`.
|
|||
----
|
||||
+
|
||||
<1> declare `int[] x`;
|
||||
assign default `null` to `x`
|
||||
store default `null` to `x`
|
||||
<2> declare `float[] y`;
|
||||
allocate `1-d float array` instance with `length [10]`
|
||||
-> `1-d float array reference`;
|
||||
assign `1-d float array reference` to `y`
|
||||
store `1-d float array reference` to `y`
|
||||
<3> declare `def z`;
|
||||
allocate `1-d float array` instance with `length [5]`
|
||||
-> `1-d float array reference`;
|
||||
implicit cast `1-d float array reference` to `def` -> `def`;
|
||||
assign `def` to `z`
|
||||
<4> access `y` -> `1-d float array reference`;
|
||||
assign `float 1.0` to `index [9]` of `1-d float array reference`
|
||||
<5> access `y` -> `1-d float array reference @0`;
|
||||
access `index [9]` of `1-d float array reference @0` -> `float 1.0`;
|
||||
access `z` -> `def`;
|
||||
store `def` to `z`
|
||||
<4> load from `y` -> `1-d float array reference`;
|
||||
store `float 1.0` to `index [9]` of `1-d float array reference`
|
||||
<5> load from `y` -> `1-d float array reference @0`;
|
||||
load from `index [9]` of `1-d float array reference @0` -> `float 1.0`;
|
||||
load from `z` -> `def`;
|
||||
implicit cast `def` to `1-d float array reference @1`
|
||||
-> `1-d float array reference @1`;
|
||||
assign `float 1.0` to `index [0]` of `1-d float array reference @1`
|
||||
store `float 1.0` to `index [0]` of `1-d float array reference @1`
|
||||
+
|
||||
* Use of a multi-dimensional array.
|
||||
* General use of a multi-dimensional array.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -457,10 +464,10 @@ the array type `int[][]`.
|
|||
<1> declare `int[][][] ia`;
|
||||
allocate `3-d int array` instance with length `[2, 3, 4]`
|
||||
-> `3-d int array reference`;
|
||||
assign `3-d int array reference` to `ia3`
|
||||
<2> access `ia3` -> `3-d int array reference`;
|
||||
assign `int 99` to `index [1, 2, 3]` of `3-d int array reference`
|
||||
store `3-d int array reference` to `ia3`
|
||||
<2> load from `ia3` -> `3-d int array reference`;
|
||||
store `int 99` to `index [1, 2, 3]` of `3-d int array reference`
|
||||
<3> declare `int i`;
|
||||
access `ia3` -> `3-d int array reference`;
|
||||
access `index [1, 2, 3]` of `3-d int array reference` -> `int 99`;
|
||||
assign `int 99` to `i`
|
||||
load from `ia3` -> `3-d int array reference`;
|
||||
load from `index [1, 2, 3]` of `3-d int array reference` -> `int 99`;
|
||||
store `int 99` to `i`
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
A variable loads and stores a value for evaluation during
|
||||
<<painless-operators, operations>>.
|
||||
|
||||
[[declaration]]
|
||||
[[variable-declaration]]
|
||||
==== Declaration
|
||||
|
||||
Declare a variable before use with the format of <<painless-types, type>>
|
||||
|
@ -12,16 +12,17 @@ followed by <<painless-identifiers, identifier>>. Declare an
|
|||
<<array-type, array type>> variable using an opening `[` token and a closing `]`
|
||||
token for each dimension directly after the identifier. Specify a
|
||||
comma-separated list of identifiers following the type to declare multiple
|
||||
variables in a single statement. Use an <<assignment, assignment operator>>
|
||||
combined with a declaration to immediately assign a value to a variable.
|
||||
A variable not immediately assigned a value will have a default value assigned
|
||||
implicitly based on the type.
|
||||
variables in a single statement. Use an
|
||||
<<variable-assignment, assignment operator>> combined with a declaration to
|
||||
immediately assign a value to a variable. A variable not immediately assigned a
|
||||
value will have a default value assigned implicitly based on the type.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If a variable is used prior to or without declaration.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
declaration : type ID assignment? (',' ID assignment?)*;
|
||||
|
@ -45,37 +46,39 @@ assignment: '=' expression;
|
|||
----
|
||||
+
|
||||
<1> declare `int x`;
|
||||
assign default `null` to `x`
|
||||
store default `null` to `x`
|
||||
<2> declare `List y`;
|
||||
assign default `null` to `y`
|
||||
store default `null` to `y`
|
||||
<3> declare `int x`;
|
||||
assign default `int 0` to `x`;
|
||||
store default `int 0` to `x`;
|
||||
declare `int y`;
|
||||
assign `int 5` to `y`;
|
||||
store `int 5` to `y`;
|
||||
declare `int z`;
|
||||
assign default `int 0` to `z`;
|
||||
store default `int 0` to `z`;
|
||||
<4> declare `def d`;
|
||||
assign default `null` to `d`
|
||||
store default `null` to `d`
|
||||
<5> declare `int i`;
|
||||
assign `int 10` to `i`
|
||||
store `int 10` to `i`
|
||||
<6> declare `float[] f`;
|
||||
assign default `null` to `f`
|
||||
store default `null` to `f`
|
||||
<7> declare `Map[][] m`;
|
||||
assign default `null` to `m`
|
||||
store default `null` to `m`
|
||||
|
||||
[[assignment]]
|
||||
[[variable-assignment]]
|
||||
==== Assignment
|
||||
|
||||
Use the *assignment operator* to store a value in a variable. Any operation
|
||||
that produces a value can be assigned to any variable as long as the
|
||||
<<painless-types, types>> are the same or the resultant type can be
|
||||
<<painless-casting, implicitly cast>> to the variable type.
|
||||
Use the `assignment operator '='` to store a value in a variable for use in
|
||||
subsequent operations. Any operation that produces a value can be assigned to
|
||||
any variable as long as the <<painless-types, types>> are the same or the
|
||||
resultant type can be <<painless-casting, implicitly cast>> to the variable
|
||||
type.
|
||||
|
||||
*Errors*
|
||||
|
||||
* If the type of value is unable to match the type of variable.
|
||||
|
||||
*Grammar*
|
||||
|
||||
[source,ANTLR4]
|
||||
----
|
||||
assignment: ID '=' expression
|
||||
|
@ -92,8 +95,8 @@ assignment: ID '=' expression
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
assign default `int 0` to `i`
|
||||
<2> assign `int 10` to `i`
|
||||
store default `int 0` to `i`
|
||||
<2> store `int 10` to `i`
|
||||
+
|
||||
* Declaration combined with immediate assignment.
|
||||
+
|
||||
|
@ -104,11 +107,11 @@ assignment: ID '=' expression
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
assign `int 10` to `i`
|
||||
store `int 10` to `i`
|
||||
<2> declare `double j`;
|
||||
assign `double 2.0` to `j`
|
||||
store `double 2.0` to `j`
|
||||
+
|
||||
* Assignment of one variable to another using primitive types.
|
||||
* Assignment of one variable to another using primitive type values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -117,12 +120,13 @@ assignment: ID '=' expression
|
|||
----
|
||||
+
|
||||
<1> declare `int i`;
|
||||
assign `int 10` to `i`
|
||||
store `int 10` to `i`
|
||||
<2> declare `int j`;
|
||||
access `i` -> `int 10`;
|
||||
assign `int 10` to `j`
|
||||
load from `i` -> `int 10`;
|
||||
store `int 10` to `j`
|
||||
+
|
||||
* Assignment with reference types using the *new instance operator*.
|
||||
* Assignment with reference types using the
|
||||
<<new-instance-operator, new instance operator>>.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -132,13 +136,13 @@ assignment: ID '=' expression
|
|||
+
|
||||
<1> declare `ArrayList l`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
assign `ArrayList reference` to `l`
|
||||
store `ArrayList reference` to `l`
|
||||
<2> declare `Map m`;
|
||||
allocate `HashMap` instance -> `HashMap reference`;
|
||||
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
|
||||
assign `Map reference` to `m`
|
||||
store `Map reference` to `m`
|
||||
+
|
||||
* Assignment of one variable to another using reference types.
|
||||
* Assignment of one variable to another using reference type values.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -151,18 +155,19 @@ assignment: ID '=' expression
|
|||
<1> declare `List l`;
|
||||
allocate `ArrayList` instance -> `ArrayList reference`;
|
||||
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
|
||||
assign `List reference` to `l`
|
||||
store `List reference` to `l`
|
||||
<2> declare `List k`;
|
||||
access `l` -> `List reference`;
|
||||
assign `List reference` to `k`;
|
||||
load from `l` -> `List reference`;
|
||||
store `List reference` to `k`;
|
||||
(note `l` and `k` refer to the same instance known as a shallow-copy)
|
||||
<3> declare `List m`;
|
||||
assign default `null` to `m`
|
||||
<4> access `k` -> `List reference`;
|
||||
assign `List reference` to `m`;
|
||||
store default `null` to `m`
|
||||
<4> load from `k` -> `List reference`;
|
||||
store `List reference` to `m`;
|
||||
(note `l`, `k`, and `m` refer to the same instance)
|
||||
+
|
||||
* Assignment with an array type variable using the *new array operator*.
|
||||
* Assignment with array type variables using the
|
||||
<<new-array-operator, new array operator>>.
|
||||
+
|
||||
[source,Painless]
|
||||
----
|
||||
|
@ -176,24 +181,24 @@ assignment: ID '=' expression
|
|||
----
|
||||
+
|
||||
<1> declare `int[] ia1`;
|
||||
assign default `null` to `ia1`
|
||||
store default `null` to `ia1`
|
||||
<2> allocate `1-d int array` instance with `length [2]`
|
||||
-> `1-d int array reference`;
|
||||
assign `1-d int array reference` to `ia1`
|
||||
<3> access `ia1` -> `1-d int array reference`;
|
||||
assign `int 1` to `index [0]` of `1-d int array reference`
|
||||
store `1-d int array reference` to `ia1`
|
||||
<3> load from `ia1` -> `1-d int array reference`;
|
||||
store `int 1` to `index [0]` of `1-d int array reference`
|
||||
<4> declare `int[] ib1`;
|
||||
access `ia1` -> `1-d int array reference`;
|
||||
assign `1-d int array reference` to `ib1`;
|
||||
load from `ia1` -> `1-d int array reference`;
|
||||
store `1-d int array reference` to `ib1`;
|
||||
(note `ia1` and `ib1` refer to the same instance known as a shallow copy)
|
||||
<5> declare `int[][] ic2`;
|
||||
allocate `2-d int array` instance with `length [2, 5]`
|
||||
-> `2-d int array reference`;
|
||||
assign `2-d int array reference` to `ic2`
|
||||
<6> access `ic2` -> `2-d int array reference`;
|
||||
assign `int 2` to `index [1, 3]` of `2-d int array reference`
|
||||
<7> access `ia1` -> `1-d int array reference`;
|
||||
access `ic2` -> `2-d int array reference`;
|
||||
assign `1-d int array reference` to
|
||||
store `2-d int array reference` to `ic2`
|
||||
<6> load from `ic2` -> `2-d int array reference`;
|
||||
store `int 2` to `index [1, 3]` of `2-d int array reference`
|
||||
<7> load from `ia1` -> `1-d int array reference`;
|
||||
load from `ic2` -> `2-d int array reference`;
|
||||
store `1-d int array reference` to
|
||||
`index [0]` of `2-d int array reference`;
|
||||
(note `ia1`, `ib1`, and `index [0]` of `ia2` refer to the same instance)
|
||||
|
|
|
@ -14,17 +14,17 @@ include::getting-started.asciidoc[]
|
|||
|
||||
include::setup.asciidoc[]
|
||||
|
||||
include::{xes-repo-dir}/setup/setup-xes.asciidoc[]
|
||||
include::setup/setup-xes.asciidoc[]
|
||||
|
||||
include::{xes-repo-dir}/monitoring/configuring-monitoring.asciidoc[]
|
||||
|
||||
include::{xes-repo-dir}/security/configuring-es.asciidoc[]
|
||||
|
||||
include::{xes-repo-dir}/setup/setup-xclient.asciidoc[]
|
||||
include::setup/setup-xclient.asciidoc[]
|
||||
|
||||
include::settings/configuring-xes.asciidoc[]
|
||||
|
||||
include::{xes-repo-dir}/setup/bootstrap-checks-xes.asciidoc[]
|
||||
include::setup/bootstrap-checks-xes.asciidoc[]
|
||||
|
||||
:edit_url:
|
||||
include::upgrade.asciidoc[]
|
||||
|
|
|
@ -1325,7 +1325,7 @@ This pipeline will insert these named captures as new fields within the document
|
|||
// NOTCONSOLE
|
||||
|
||||
[[custom-patterns]]
|
||||
==== Custom Patterns and Pattern Files
|
||||
==== Custom Patterns
|
||||
|
||||
The Grok processor comes pre-packaged with a base set of pattern. These patterns may not always have
|
||||
what you are looking for. Pattern have a very basic format. Each entry describes has a name and the pattern itself.
|
||||
|
|
|
@ -115,7 +115,7 @@ PUT my_index/_doc/1
|
|||
[[match-unmatch]]
|
||||
==== `match` and `unmatch`
|
||||
|
||||
The `match` parameter uses a pattern to match on the fieldname, while
|
||||
The `match` parameter uses a pattern to match on the field name, while
|
||||
`unmatch` uses a pattern to exclude fields matched by `match`.
|
||||
|
||||
The following example matches all `string` fields whose name starts with
|
||||
|
@ -259,7 +259,7 @@ PUT my_index/_doc/1
|
|||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
<1> The `english` field is mapped as a `string` field with the `english` analyzer.
|
||||
<2> The `count` field is mapped as a `long` field with `doc_values` disabled
|
||||
<2> The `count` field is mapped as a `long` field with `doc_values` disabled.
|
||||
|
||||
[[template-examples]]
|
||||
==== Template examples
|
||||
|
|
|
@ -100,11 +100,6 @@ PUT my_index/_mapping/_doc
|
|||
<1> The mapping that you specify for `my_field` should consist of the existing
|
||||
mapping for that field, plus the `fielddata` parameter.
|
||||
|
||||
TIP: The `fielddata.*` parameter must have the same settings for fields of the
|
||||
same name in the same index. Its value can be updated on existing fields
|
||||
using the <<indices-put-mapping,PUT mapping API>>.
|
||||
|
||||
|
||||
[[field-data-filtering]]
|
||||
==== `fielddata_frequency_filter`
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ string:: <<text,`text`>> and <<keyword,`keyword`>>
|
|||
|
||||
<<feature>>:: Record numeric features to boost hits at query time.
|
||||
|
||||
<<feature-vector>>:: Record numeric feature vectors to boost hits at query time.
|
||||
|
||||
[float]
|
||||
=== Multi-fields
|
||||
|
||||
|
@ -90,4 +92,4 @@ include::types/parent-join.asciidoc[]
|
|||
|
||||
include::types/feature.asciidoc[]
|
||||
|
||||
|
||||
include::types/feature-vector.asciidoc[]
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
[[feature-vector]]
|
||||
=== Feature vector datatype
|
||||
|
||||
A `feature_vector` field can index numeric feature vectors, so that they can
|
||||
later be used to boost documents in queries with a
|
||||
<<query-dsl-feature-query,`feature`>> query.
|
||||
|
||||
It is analogous to the <<feature,`feature`>> datatype but is better suited
|
||||
when the list of features is sparse so that it wouldn't be reasonable to add
|
||||
one field to the mappings for each of them.
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
PUT my_index
|
||||
{
|
||||
"mappings": {
|
||||
"_doc": {
|
||||
"properties": {
|
||||
"topics": {
|
||||
"type": "feature_vector" <1>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PUT my_index/_doc/1
|
||||
{
|
||||
"topics": { <2>
|
||||
"politics": 20,
|
||||
"economics": 50.8
|
||||
}
|
||||
}
|
||||
|
||||
PUT my_index/_doc/2
|
||||
{
|
||||
"topics": {
|
||||
"politics": 5.2,
|
||||
"sports": 80.1
|
||||
}
|
||||
}
|
||||
|
||||
GET my_index/_search
|
||||
{
|
||||
"query": {
|
||||
"feature": {
|
||||
"field": "topics.politics"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
<1> Feature vector fields must use the `feature_vector` field type
|
||||
<2> Feature vector fields must be a hash with string keys and strictly positive numeric values
|
||||
|
||||
NOTE: `feature_vector` fields only support single-valued features and strictly
|
||||
positive values. Multi-valued fields and zero or negative values will be rejected.
|
||||
|
||||
NOTE: `feature_vector` fields do not support sorting or aggregating and may
|
||||
only be queried using <<query-dsl-feature-query,`feature`>> queries.
|
||||
|
||||
NOTE: `feature_vector` fields only preserve 9 significant bits for the
|
||||
precision, which translates to a relative error of about 0.4%.
|
||||
|
|
@ -84,3 +84,9 @@ for a particular index with the index setting `index.max_regex_length`.
|
|||
|
||||
Search requests with extra content after the main object will no longer be accepted
|
||||
by the `_search` endpoint. A parsing exception will be thrown instead.
|
||||
|
||||
==== Semantics changed for `max_concurrent_shard_requests`
|
||||
|
||||
`max_concurrent_shard_requests` used to limit the total number of concurrent shard
|
||||
requests a single high level search request can execute. In 7.0 this changed to be the
|
||||
max number of concurrent shard requests per node. The default is now `5`.
|
||||
|
|
|
@ -325,5 +325,5 @@ the <<cluster.name,`cluster.name`>>, the <<node.name,`node.name`>> and the
|
|||
<<modules-network,network settings>>.
|
||||
|
||||
ifdef::include-xpack[]
|
||||
include::{xes-repo-dir}/node.asciidoc[]
|
||||
include::ml-node.asciidoc[]
|
||||
endif::include-xpack[]
|
||||
|
|
|
@ -44,7 +44,12 @@ time setting format). Defaults to `30s`.
|
|||
|`transport.tcp.compress` |Set to `true` to enable compression (`DEFLATE`)
|
||||
between all nodes. Defaults to `false`.
|
||||
|
||||
|`transport.ping_schedule` | Schedule a regular ping message to ensure that connections are kept alive. Defaults to `5s` in the transport client and `-1` (disabled) elsewhere.
|
||||
|`transport.ping_schedule` | Schedule a regular application-level ping message
|
||||
to ensure that transport connections between nodes are kept alive. Defaults to
|
||||
`5s` in the transport client and `-1` (disabled) elsewhere. It is preferable to
|
||||
correctly configure TCP keep-alives instead of using this feature, because TCP
|
||||
keep-alives apply to all kinds of long-lived connection and not just to
|
||||
transport connections.
|
||||
|
||||
|=======================================================================
|
||||
|
||||
|
@ -80,6 +85,20 @@ The following parameters can be configured like that
|
|||
* `tcp_send_buffer_size`: Configures the send buffer size of the socket
|
||||
* `tcp_receive_buffer_size`: Configures the receive buffer size of the socket
|
||||
|
||||
[float]
|
||||
==== Long-lived idle connections
|
||||
|
||||
Elasticsearch opens a number of long-lived TCP connections between each pair of
|
||||
nodes in the cluster, and some of these connections may be idle for an extended
|
||||
period of time. Nonetheless, Elasticsearch requires these connections to remain
|
||||
open, and it can disrupt the operation of the cluster if any inter-node
|
||||
connections are closed by an external influence such as a firewall. It is
|
||||
important to configure your network to preserve long-lived idle connections
|
||||
between Elasticsearch nodes, for instance by leaving `tcp_keep_alive` enabled
|
||||
and ensuring that the keepalive interval is shorter than any timeout that might
|
||||
cause idle connections to be closed, or by setting `transport.ping_schedule` if
|
||||
keepalives cannot be configured.
|
||||
|
||||
[float]
|
||||
=== Transport Tracer
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
=== Feature Query
|
||||
|
||||
The `feature` query is a specialized query that only works on
|
||||
<<feature,`feature`>> fields. Its goal is to boost the score of documents based
|
||||
on the values of numeric features. It is typically put in a `should` clause of
|
||||
a <<query-dsl-bool-query,`bool`>> query so that its score is added to the score
|
||||
<<feature,`feature`>> fields and <<feature-vector,`feature_vector`>> fields.
|
||||
Its goal is to boost the score of documents based on the values of numeric
|
||||
features. It is typically put in a `should` clause of a
|
||||
<<query-dsl-bool-query,`bool`>> query so that its score is added to the score
|
||||
of the query.
|
||||
|
||||
Compared to using <<query-dsl-function-score-query,`function_score`>> or other
|
||||
|
@ -13,7 +14,16 @@ efficiently skip non-competitive hits when
|
|||
<<search-uri-request,`track_total_hits`>> is set to `false`. Speedups may be
|
||||
spectacular.
|
||||
|
||||
Here is an example:
|
||||
Here is an example that indexes various features:
|
||||
- https://en.wikipedia.org/wiki/PageRank[`pagerank`], a measure of the
|
||||
importance of a website,
|
||||
- `url_length`, the length of the url, which typically correlates negatively
|
||||
with relevance,
|
||||
- `topics`, which associates a list of topics with every document alongside a
|
||||
measure of how well the document is connected to this topic.
|
||||
|
||||
Then the example includes an example query that searches for `"2016"` and boosts
|
||||
based or `pagerank`, `url_length` and the `sports` topic.
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
|
@ -28,6 +38,9 @@ PUT test
|
|||
"url_length": {
|
||||
"type": "feature",
|
||||
"positive_score_impact": false
|
||||
},
|
||||
"topics": {
|
||||
"type": "feature_vector"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,14 +49,39 @@ PUT test
|
|||
|
||||
PUT test/_doc/1
|
||||
{
|
||||
"pagerank": 10,
|
||||
"url_length": 50
|
||||
"url": "http://en.wikipedia.org/wiki/2016_Summer_Olympics",
|
||||
"content": "Rio 2016",
|
||||
"pagerank": 50.3,
|
||||
"url_length": 42,
|
||||
"topics": {
|
||||
"sports": 50,
|
||||
"brazil": 30
|
||||
}
|
||||
}
|
||||
|
||||
PUT test/_doc/2
|
||||
{
|
||||
"pagerank": 100,
|
||||
"url_length": 20
|
||||
"url": "http://en.wikipedia.org/wiki/2016_Brazilian_Grand_Prix",
|
||||
"content": "Formula One motor race held on 13 November 2016 at the Autódromo José Carlos Pace in São Paulo, Brazil",
|
||||
"pagerank": 50.3,
|
||||
"url_length": 47,
|
||||
"topics": {
|
||||
"sports": 35,
|
||||
"formula one": 65,
|
||||
"brazil": 20
|
||||
}
|
||||
}
|
||||
|
||||
PUT test/_doc/3
|
||||
{
|
||||
"url": "http://en.wikipedia.org/wiki/Deadpool_(film)",
|
||||
"content": "Deadpool is a 2016 American superhero film",
|
||||
"pagerank": 50.3,
|
||||
"url_length": 37,
|
||||
"topics": {
|
||||
"movies": 60,
|
||||
"super hero": 65
|
||||
}
|
||||
}
|
||||
|
||||
POST test/_refresh
|
||||
|
@ -51,17 +89,33 @@ POST test/_refresh
|
|||
GET test/_search
|
||||
{
|
||||
"query": {
|
||||
"feature": {
|
||||
"field": "pagerank"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GET test/_search
|
||||
{
|
||||
"query": {
|
||||
"feature": {
|
||||
"field": "url_length"
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"match": {
|
||||
"content": "2016"
|
||||
}
|
||||
}
|
||||
],
|
||||
"should": [
|
||||
{
|
||||
"feature": {
|
||||
"field": "pagerank"
|
||||
}
|
||||
},
|
||||
{
|
||||
"feature": {
|
||||
"field": "url_length",
|
||||
"boost": 0.1
|
||||
}
|
||||
},
|
||||
{
|
||||
"feature": {
|
||||
"field": "topics.sports",
|
||||
"boost": 0.4
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,6 +241,13 @@ number of terms that must match.
|
|||
The syntax is the same as the <<query-dsl-minimum-should-match,minimum should match>>.
|
||||
(Defaults to `"30%"`).
|
||||
|
||||
`fail_on_unsupported_field`::
|
||||
Controls whether the query should fail (throw an exception) if any of the
|
||||
specified fields are not of the supported types
|
||||
(`text` or `keyword'). Set this to `false` to ignore the field and continue
|
||||
processing. Defaults to
|
||||
`true`.
|
||||
|
||||
`boost_terms`::
|
||||
Each term in the formed query could be further boosted by their tf-idf score.
|
||||
This sets the boost factor to use when using this feature. Defaults to
|
||||
|
|
|
@ -37,10 +37,9 @@ GET /_search
|
|||
--------------------------------------------------
|
||||
// CONSOLE
|
||||
|
||||
WARNING: By default `span_multi queries are rewritten to a `span_or` query
|
||||
containing **all** the expanded terms. This can be expensive if the number of expanded
|
||||
terms is large. To avoid an unbounded expansion you can set the
|
||||
<<query-dsl-multi-term-rewrite,rewrite method>> of the multi term query to `top_terms_*`
|
||||
rewrite. Or, if you use `span_multi` on `prefix` query only, you can
|
||||
activate the <<index-prefix-config,`index_prefixes`>> field option of the `text` field instead. This will
|
||||
WARNING: `span_multi` queries will hit too many clauses failure if the number of terms that match the query exceeds the
|
||||
boolean query limit (defaults to 1024).To avoid an unbounded expansion you can set the <<query-dsl-multi-term-rewrite,
|
||||
rewrite method>> of the multi term query to `top_terms_*` rewrite. Or, if you use `span_multi` on `prefix` query only,
|
||||
you can activate the <<index-prefix-config,`index_prefixes`>> field option of the `text` field instead. This will
|
||||
rewrite any prefix query on the field to a a single term query that matches the indexed prefix.
|
||||
|
||||
|
|
|
@ -288,8 +288,9 @@ GET /_search
|
|||
"pin.location" : [-70, 40],
|
||||
"order" : "asc",
|
||||
"unit" : "km",
|
||||
"mode" : "min",
|
||||
"distance_type" : "arc"
|
||||
"mode" : "min",
|
||||
"distance_type" : "arc",
|
||||
"ignore_unmapped": true
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -317,6 +318,12 @@ GET /_search
|
|||
|
||||
The unit to use when computing sort values. The default is `m` (meters).
|
||||
|
||||
|
||||
`ignore_unmapped`::
|
||||
|
||||
Indicates if the unmapped field should be treated as a missing value. Setting it to `true` is equivalent to specifying
|
||||
an `unmapped_type` in the field sort. The default is `false` (unmapped field are causing the search to fail).
|
||||
|
||||
NOTE: geo distance sorting does not support configurable missing values: the
|
||||
distance will always be considered equal to +Infinity+ when a document does not
|
||||
have values for the field that is used for distance computation.
|
||||
|
|
|
@ -87,7 +87,7 @@ Controls how often to roll over to a new index: `hourly`, `daily`, `weekly`, or
|
|||
`xpack.security.audit.index.events.include`::
|
||||
Specifies the audit events to be indexed. The default value is
|
||||
`anonymous_access_denied, authentication_failed, realm_authentication_failed, access_granted, access_denied, tampered_request, connection_granted, connection_denied, run_as_granted, run_as_denied`.
|
||||
See {xpack-ref}/auditing.html#audit-event-types[Audit Entry Types] for the
|
||||
See {xpack-ref}/audit-event-types.html[Audit Entry Types] for the
|
||||
complete list.
|
||||
|
||||
`xpack.security.audit.index.events.exclude`::
|
||||
|
|
|
@ -65,6 +65,5 @@ include::install/rpm.asciidoc[]
|
|||
|
||||
include::install/windows.asciidoc[]
|
||||
|
||||
ifdef::include-xpack[]
|
||||
include::{xes-repo-dir}/setup/docker.asciidoc[]
|
||||
endif::include-xpack[]
|
||||
include::install/docker.asciidoc[]
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ ifdef::include-xpack[]
|
|||
==== Enable automatic creation of {xpack} indices
|
||||
|
||||
{xpack} will try to automatically create a number of indices within Elasticsearch.
|
||||
include::{xes-repo-dir}/setup/xpack-indices.asciidoc[]
|
||||
include::xpack-indices.asciidoc[]
|
||||
|
||||
endif::include-xpack[]
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
[role="xpack"]
|
||||
[[docker]]
|
||||
=== Install {es} with Docker
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
[role="exclude"]
|
||||
==== Next steps
|
||||
|
||||
You now have a test Elasticsearch environment set up. Before you start
|
||||
serious development or go into production with Elasticsearch, you will need to
|
||||
do some additional setup:
|
||||
You now have a test {es} environment set up. Before you start
|
||||
serious development or go into production with {es}, you must do some additional
|
||||
setup:
|
||||
|
||||
* Learn how to <<settings,configure Elasticsearch>>.
|
||||
* Configure <<important-settings,important Elasticsearch settings>>.
|
||||
* Configure <<system-config,important system settings>>.
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ ifdef::include-xpack[]
|
|||
==== Enable automatic creation of {xpack} indices
|
||||
|
||||
{xpack} will try to automatically create a number of indices within {es}.
|
||||
include::{xes-repo-dir}/setup/xpack-indices.asciidoc[]
|
||||
include::xpack-indices.asciidoc[]
|
||||
|
||||
endif::include-xpack[]
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue