Java client's scripts api

Hi, Thank you for your work!

I am trying to use Indexed Scripts API from java.

This is the tutorial that I tested.
my client does not have those methods and Response classes.

I am using elastic cloud(v5.5.1).

What is the correct way to use 'Indexed Scripts API'.

code

		PutIndexedScriptResponse = client.preparePutIndexedScript()
                     .setScriptLang("painless")
                     .setId("script1")
                     .setSource("script", "_score * doc['my_numeric_field'].value")
                     .execute()
                     .actionGet();

        GetIndexedScriptResponse = client.prepareGetIndexedScript()
                        .setScriptLang("painless")
                        .setId("script1")
                        .execute()
                        .actionGet();

        DeleteIndexedScriptResponse = client.prepareDeleteIndexedScript()
                        .setScriptLang("painless")
                        .setId("script1")
                        .execute()
                        .actionGet();

POM

    <dependency>
		<groupId>org.elasticsearch.client</groupId>
		<artifactId>transport</artifactId>
		<version>5.5.1</version>
	</dependency>
	<dependency>
		<groupId>org.elasticsearch.client</groupId>
		<artifactId>rest</artifactId>
		<version>5.5.1</version>
	</dependency>

	<dependency>
		<groupId>org.elasticsearch.client</groupId>
		<artifactId>x-pack-transport</artifactId>
		<version>5.5.0</version>
	</dependency>

client

   TransportClient javaClient = new PreBuiltXPackTransportClient(settings)
			        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(fullhost), 9343));

client works fine for other functions.

error

    1. PutIndexedScriptResponse cannot be resolved to a variable
    2. The method preparePutIndexedScript() is undefined for the type TransportClient

Thanks.
HJ.

Better not to use images for code parts. Could you update your post please?
Don't forget to use code formatting with </> icon.

Thanks.

Have a look at client.admin().cluster().putStoredScript(). That's probably what you are looking at.

1 Like

I changed images!

and where can i find docs for client.admin().cluster().putStoredScript()?

I could not find any information for client.admin().cluster().putStoredScript() in here.
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin.html

There is no documentation on this.

Just the javadoc and the source code.
You can look in elasticsearch repository and search for tests using that method. That can really help

1 Like

thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.