0
votes

I've installed x-pack into my elasticsearch: curl --user u:p 'localhost:9200/_xpack':

{
  "build" : {
    "hash" : "e016ba5",
    "date" : "2017-01-24T20:17:08.168Z"
  },
  "license" : {
    "uid" : "a5a93479-cdd1-44c0-8669-78a3ae1cbfeb",
    "type" : "trial",
    "mode" : "trial",
    "status" : "active",
    "expiry_date_in_millis" : 1491567639615
  },
  "features" : {
    "graph" : {
      "description" : "Graph Data Exploration for the Elastic Stack",
      "available" : true,
      "enabled" : false
    },
    "monitoring" : {
      "description" : "Monitoring for the Elastic Stack",
      "available" : true,
      "enabled" : false
    },
    "security" : {
      "description" : "Security for the Elastic Stack",
      "available" : true,
      "enabled" : true
    },
    "watcher" : {
      "description" : "Alerting, Notification and Automation for the Elastic Stack",
      "available" : true,
      "enabled" : false
    }
  },
  "tagline" : "You know, for X"
}

This is my code in order to build my client:

Settings settings = Settings.builder()
        .put(ElasticsearchApplicationResources.ELASTICSEARCH_PROPERTY_CLUSTER_NAME, this.configurationResources.getElasticsearchCluserName())
    .put("xpack.security.user", "elastic:changeme")
    .build();

    List<InetSocketTransportAddress> addresses = ...;

    try {
     this.elasticsearchClient = new PreBuiltTransportClient(settings)
        .addTransportAddresses(addresses.toArray(new InetSocketTransportAddress[addresses.size()]));
    }catch (Exception e)
    {
    System.out.print(e);
    }

Currently, I'm getting this message:

java.lang.IllegalArgumentException: unknown setting [xpack.security.user] please check that any required plugins are installed, or check the breaking changes documentation for removed settings

Any ideas?

1

1 Answers

0
votes

Well, you need add this dependency in your 'pom.xml'

<repositories>
    <!-- add the elasticsearch repo -->
    <repository>
        <id>elasticsearch-releases</id>
        <url>https://artifacts.elastic.co/maven</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>x-pack-transport</artifactId>
    <version>${org.elasticsearch.version}</version>
</dependency>

next, update your java code,

import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;  

this.elasticsearchClient = new PreBuiltXPackTransportClient(settings)
    .addTransportAddresses(addresses.toArray(new InetSocketTransportAddress[addresses.size()]));

and then, try again~