I am trying to connect to elasticsearch with Resthighlevelclient and it is was working ok when i hard code the host, port and schema inside the code. But when I am using application.yml for defining the port, schema, hostname, and cluster name, I get an error saying Hostname may not be null.
I am using this for connecting to elasticsearch.
some of the code I am using are:
@Value ("{elasticsearch.host}")
private static String HOST;
//private static final String HOST = "localhost";
@Value ( "{elasticsearch.port_one}" )
private int PORT_ONE;
//private static final int PORT_ONE = 9200; @Value ( "{elasticsearch.port_two}" )
private int PORT_TWO;
//private static final int PORT_TWO = 9201;
@Value ( "{elasticsearch.schema}" )
private String SCHEME ;
my application.yml looks like this:
elasticsearch:
port_one: 9200
port_two: 9201
index: "test_data"
clustername: "testing_elasticsearch"
type: "testinges"
schema: "http"
host: "localhost"
I can tell the application.yml and the code are not communicating. This might be a silly question, but I am new to elasticsearch and please bear with me.
Do I have to create a configuration class or did I miss something? If so, I do not know how to define a configuration class and I tried to find a code example, found nothing helpful.
Can anyone please give me some idea what to do or show me how to define configuration class for highrestlevelclient and use application.yml configuration?
I highly appreciate your help. Thanks.
Could you print what are the exact values used to create the client?
If they are incorrect then that's more a problem to solve in spring forums IMO (or whatever framework you're using).
I have checked and they are null for SCHEMA and HOST and 0 for PORT_ONE and PORT_TWO.
Though the values are on application.yml, at run time it is not getting the values. How can I make this work using the application.yml ? Sorry if this sounds a silly question. As I told you, I am new for spring framework and Elasticsearch. Thank you very much for your help.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.