After thinking a lot about what to write next, I stumbled upon a very cool idea.
And this is what I thought I should do: Discover something interesting using code ?
Let’s find out what’s the most popular drink among tea, coffee and beer in the world? All using code!!!
Yes, you heard it right.
How do we do this?
First and foremost, we need data!! And by data, I mean real time data because trends may change day to day. Social media is full of data, and we should thank Twitter for writing a Java HTTP client for streaming real-time Tweets using Twitter’s own Streaming API.
This client is known as Hosebird Client (hbc). Though it was written by Twitter a long time back and Twitter has deprecated some of its features but it will perfectly work for our requirement.
Also, we need to store the streaming data into some data-store and for this purpose we’ll be using Elasticsearch.
Why Elasticsearch?
The sole purpose of using Elasticsearch is to use Kibana’s Canvas to further visualise the data.
Canvas is a whole new way of making data look amazing. Canvas combines data with colours, shapes, text, and your own imagination to bring dynamic, multi-page, pixel-perfect, data displays to screens large and small.
Elastic
In simple words it is an application which lets you visualise data stored in Elasticsearch in a better and customised way in real time (while data is being ingested in Elasticsearch) and is currently in beta release.
You’ll be thrilled to see the end result using Elasticsearch Canvas.
Note: For the demonstration Elasticsearch & Kibana 6.5.2 are used.
Prerequisites:
- Make sure Elasticsearch and Kibana are installed.
Let’s get started. Cheers to the beginning ?
Follow the steps below to implement the above concept:
1) Setting up a maven project:
1.1) Create a Maven Project (for the demonstration I am using Eclipse IDE, you can use any IDE):
1.2) Skip the archetype selection:
1.3) Add the Group Id, Artifact Id and Name, then click Finish:
2) Configuring the maven project:
2.1) Open the pom.xml and add the following dependencies:
<dependencies>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>hbc-core</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>6.5.2</version>
</dependency>
</dependencies>
These are the Java client libraries of Twitter and Elasticsearch.
2.2) Configuring the maven-compiler-plugin to use Java 8:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
2.3) After this update the maven project:
Alternately you can also press Alt+F5 after selecting the project.
3) Create an Application class:
3.1) Go to src/main/java and create a new class:
3.2) Add the Package and Name of the class then click Finish:
4) Configure the Twitter Java Client:
4.1) Create a static method createTwitterClient in Application class and add the following lines of code:
public static Client createTwitterClient(BlockingQueue<String> msgQueue, List<String> terms) {
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
hosebirdEndpoint.trackTerms(terms); // tweets with the specified terms
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);
ClientBuilder builder = new ClientBuilder().name("Twitter-Elastic-Client").hosts(hosebirdHosts)
.authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
.processor(new StringDelimitedProcessor(msgQueue));
Client hosebirdClient = builder.build();
return hosebirdClient;
}
Notice, that this method expects two arguments: one is the BlockingQueue which is used as a message queue for the tweets and another is the List of terms we want our tweets to be filtered with (in our case “tea”, “coffee” & “beer”). So we are configuring our client to return real time filtered tweets (tweets with terms “tea”, “coffee” or “beer”).
Notice the line of code shown below:
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);
Twitter Java Client uses OAuth to provide authorised access to the Streaming API, which requires you to have the consumer/access keys and tokens.
So to stream Twitter data you must have the consumer/access keys and tokens.
4.2) Getting Twitter Consumer API/Access token keys:
Follow the link Getting Twitter Consumer API/Access token keys to obtain the keys and tokens.
After getting the Consumer API key, Consumer API secret key, Access token and Access token secret,add them as Strings in the Application class:
private final static String consumerKey = "xxxxxxxxxxxxxxxxxx";
private final static String consumerSecret = "xxxxxxxxxxxxxxxxxx";
private final static String token = "xxxxxxxxxxxxxxxxxx";
private final static String secret = "xxxxxxxxxxxxxxxxxx";
It is not advisable to put this info in the program itself and should be read from a config file but for brevity I am putting these values in Application class as static final Strings.
5) Configure the Elasticsearch Transport Client:
5.1) Create a static method createElasticTransportClient in Application class and add the following lines of code:
public static TransportClient createElasticTransportClient() throws UnknownHostException {
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}
The above method returns a Transport Client which talks to locally running Elasticsearch on port 9300.
If your Elasticsearch is running on some other port or host then you may need to change the values of “localhost” to your “host” and “9300” to your “port”, if your Elasticsearch cluster name is different that “elasticsearch”, then you need to create the client like this:
TransportClient client = new PreBuiltTransportClient(Settings.builder().put("cluster.name", "myClusterName").build())
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
6) Streaming data from twitter:
Once the client establishes a connection:
// establish a connection
client.connect();
The blocking queue will now start being filled with messages. However we would like to read only first 1000 messages from the queue:
int count = 0;
while (!client.isDone() && count != 1000) {
String msg = msgQueue.take(); // reading a tweet
// Segregating the tweet and writing result to elasticsearch
count++;
}
7) Segregating tweets based on terms and then indexing the segregated result to Elasticsearch:
For brevity I am streaming first 1000 tweets (containing terms “tea”, “coffee” & “beer”), segregating them one by one and indexing the results in Elasticsearch.
Example: Let’s say if a tweet contains the term “ tea ” then I will index the following document into Elasticsearch:
{ “tweet” : “tea” }
One thing I would like to clear: Let’s say if a tweet has tea and coffee both then I will consider only the first term. However, if you want to consider both the terms then hack into my repo stated at the end of this article.
This is how the complete Application class looks like:
package com.technocratsid.elastic;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import com.google.common.collect.Lists;
import com.twitter.hbc.ClientBuilder;
import com.twitter.hbc.core.Client;
import com.twitter.hbc.core.Constants;
import com.twitter.hbc.core.Hosts;
import com.twitter.hbc.core.HttpHosts;
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint;
import com.twitter.hbc.core.processor.StringDelimitedProcessor;
import com.twitter.hbc.httpclient.auth.Authentication;
import com.twitter.hbc.httpclient.auth.OAuth1;
public class Application {
private final static String consumerKey = "xxxxxxxxxxxxxxxxxx";
private final static String consumerSecret = "xxxxxxxxxxxxxxxxxx";
private final static String token = "xxxxxxxxxxxxxxxxxx";
private final static String secret = "xxxxxxxxxxxxxxxxxx";
private static Logger logger = Logger.getLogger(Application.class.getName());
public static void main(String[] args) {
BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(1000);
List<String> terms = Lists.newArrayList("tea", "coffee", "beer");
// Elasticsearch Transport Client
TransportClient elasticClient = createElasticTransportClient();
// Twitter HoseBird Client
Client client = createTwitterClient(msgQueue, terms);
client.connect();
String msg = null;
int count = 0;
// Streaming 1000 tweets
while (!client.isDone() && count != 1000) {
try {
msg = msgQueue.take();
logger.log(Level.INFO, msg);
// Segregating the tweets
if (msg.contains(" tea ")) {
insertIntoElastic(elasticClient, "tea");
} else if (msg.contains(" coffee ")) {
insertIntoElastic(elasticClient, "coffee");
} else {
insertIntoElastic(elasticClient, "beer");
}
count++;
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, ex.getMessage());
client.stop();
}
}
// Closing the clients
client.stop();
elasticClient.close();
}
public static Client createTwitterClient(BlockingQueue<String> msgQueue, List<String> terms) {
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
hosebirdEndpoint.trackTerms(terms); // tweets with the specified terms
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);
ClientBuilder builder = new ClientBuilder().name("Twitter-Elastic-Client").hosts(hosebirdHosts)
.authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
.processor(new StringDelimitedProcessor(msgQueue));
Client hosebirdClient = builder.build();
return hosebirdClient;
}
@SuppressWarnings("resource")
public static TransportClient createElasticTransportClient() {
TransportClient client = null;
try {
client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
} catch (UnknownHostException ex) {
logger.log(Level.SEVERE, ex.getMessage());
}
return client;
}
public static void insertIntoElastic(TransportClient client, String tweet) {
try {
client.prepareIndex("drink-popularity", "_doc")
.setSource(jsonBuilder().startObject().field("tweet", tweet).endObject()).get();
} catch (IOException e) {
e.printStackTrace();
}
}
}
8) Configuring Canvas in Kibana:
Make sure your Kibana server is running. Mine is running locally at http://localhost:5601.
8.1) Go to http://localhost:5601.
8.2) Go to Dev Tools and perform the following requests:
PUT drink-popularity
The above PUT request creates an index drink-popularity.
PUT drink-popularity/_mapping/_doc
{
"properties": {
"tweet" : {
"type" : "keyword"
}
}
}
The above request adds a new field tweet to the _doc mapping type.
8.3) Go to Canvas:
8.4) I have already created a Canvas workpad. You just need to download it from here and import it in your own Canvas by clicking on Import workpad JSON file and then selecting the downloaded JSON file.
8.5) Once you have imported the workpad, open it by clicking on Drink Popularity workpad from Canvas workpads list.
This is what you should see:
Now click on No of tweets metric:
On the side panel of Selected Layer click on Data:
Notice the Elasticsearch SQL query used to fetch total no of tweets. Looks familiar right?
The above Elasticsearch SQL counts the total number of documents in drink-popularity index.
Do the same for one of the Horizontal progress bars:
Notice the Data panel:
So the above query is counting the no of tweets where tweet = ‘tea’ and dividing it by total no of tweets i.e. 1000.
Same thing has been done for other two progress bars.
9) Run the program to see live results in Canvas:
Before running the program the initial Canvas looks like this:
Now run the Application class and enable the auto-refresh in Canvas to see live updates and notice the Canvas.
After sometime:
In the end:
Cheers !!! Beer is the winner 🙂 You can also check the results for a specific location by filtering the tweets based on location.
I hope you guys like the concept.
Feel free to hack into the github repo.
4 thoughts on “Exploring Twitter Data using Elasticseach & Kibana’s Canvas”
Comments are closed.
Nice JOB !, I discovered elastic’s new features following your tutorial ,”CANVAS & Elasticsearch Sql”.
Canvas make Kibana more beautiful to see, Iused the Json API Request last year to query data it’s cool but elasticsearch SQL is faster.
Glad you liked it 🙂 Stay tuned for more tutorials like this.
I am getting the following error when I try to run the application. Any idea why ?
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: no modules loaded
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
Dec 04, 2019 2:54:44 PM org.elasticsearch.plugins.PluginsService logPluginInfo
INFO: loaded plugin [org.elasticsearch.transport.Netty4Plugin]
Dec 04, 2019 2:54:48 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
WARNING: node {#transport#-1}{IwL_x4a-TmavamPjAcYgIQ}{localhost}{127.0.0.1:9300} not part of the cluster Cluster [elasticsearch], ignoring…
Dec 04, 2019 2:54:48 PM com.twitter.hbc.httpclient.BasicClient connect
INFO: New connection executed: Twitter-Elastic-Client, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
Dec 04, 2019 2:54:49 PM com.twitter.hbc.httpclient.ClientBase establishConnection
INFO: Twitter-Elastic-Client Establishing a connection
Dec 04, 2019 2:54:50 PM com.twitter.hbc.httpclient.ClientBase processConnectionData
INFO: Twitter-Elastic-Client Processing connection data
Dec 04, 2019 2:54:50 PM elastic.App main
INFO: {“created_at”:”Wed Dec 04 13:53:15 +0000 2019″,”id”:1202224347735183362,”id_str”:”1202224347735183362″,”text”:”RT @MnetMAMA: [#2019MAMA] Call from #GOT7\n\nThe energy from @GOT7Official is over the top ready for MAMA\ud83e\udd70 They give a little tea about their\u2026″,”source”:”\u003ca href=\”http:\/\/twitter.com\/download\/android\” rel=\”nofollow\”\u003eTwitter for Android\u003c\/a\u003e”,”truncated”:false,”in_reply_to_status_id”:null,”in_reply_to_status_id_str”:null,”in_reply_to_user_id”:null,”in_reply_to_user_id_str”:null,”in_reply_to_screen_name”:null,”user”:{“id”:967682604525760512,”id_str”:”967682604525760512″,”name”:”\u2764\ufe0f\ud83c\udf43YOU\ud83c\udf43\u2764\ufe0f”,”screen_name”:”lapanantrakul”,”location”:null,”url”:null,”description”:”\ud83c\udf41\ud83c\udf41\ud83e\udd40\ud83e\udd40\ud83c\udf43\ud83c\udf43″,”translator_type”:”none”,”protected”:false,”verified”:false,”followers_count”:5,”friends_count”:231,”listed_count”:0,”favourites_count”:532,”statuses_count”:395,”created_at”:”Sun Feb 25 08:48:06 +0000 2018″,”utc_offset”:null,”time_zone”:null,”geo_enabled”:false,”lang”:null,”contributors_enabled”:false,”is_translator”:false,”profile_background_color”:”F5F8FA”,”profile_background_image_url”:””,”profile_background_image_url_https”:””,”profile_background_tile”:false,”profile_link_color”:”1DA1F2″,”profile_sidebar_border_color”:”C0DEED”,”profile_sidebar_fill_color”:”DDEEF6″,”profile_text_color”:”333333″,”profile_use_background_image”:true,”profile_image_url”:”http:\/\/pbs.twimg.com\/profile_images\/1164030969252200448\/q5cfClWm_normal.jpg”,”profile_image_url_https”:”https:\/\/pbs.twimg.com\/profile_images\/1164030969252200448\/q5cfClWm_normal.jpg”,”profile_banner_url”:”https:\/\/pbs.twimg.com\/profile_banners\/967682604525760512\/1542370270″,”default_profile”:true,”default_profile_image”:false,”following”:null,”follow_request_sent”:null,”notifications”:null},”geo”:null,”coordinates”:null,”place”:null,”contributors”:null,”retweeted_status”:{“created_at”:”Tue Dec 03 05:30:00 +0000 2019″,”id”:1201735312201773057,”id_str”:”1201735312201773057″,”text”:”[#2019MAMA] Call from #GOT7\n\nThe energy from @GOT7Official is over the top ready for MAMA\ud83e\udd70 They give a little tea a\u2026 https:\/\/t.co\/BujGdLVNv3″,”display_text_range”:[0,140],”source”:”\u003ca href=\”https:\/\/studio.twitter.com\” rel=\”nofollow\”\u003eTwitter Media Studio\u003c\/a\u003e”,”truncated”:true,”in_reply_to_status_id”:null,”in_reply_to_status_id_str”:null,”in_reply_to_user_id”:null,”in_reply_to_user_id_str”:null,”in_reply_to_screen_name”:null,”user”:{“id”:128487133,”id_str”:”128487133″,”name”:”MAMA(\uc5e0\ub137\uc544\uc2dc\uc548\ubba4\uc9c1\uc5b4\uc6cc\uc988)”,”screen_name”:”MnetMAMA”,”location”:”Seoul, South Korea”,”url”:”http:\/\/2019mama.com”,”description”:”MAMA(Mnet Asian Music Awards) Official Twitter”,”translator_type”:”none”,”protected”:false,”verified”:true,”followers_count”:1853665,”friends_count”:295,”listed_count”:2338,”favourites_count”:2,”statuses_count”:9813,”created_at”:”Thu Apr 01 07:54:34 +0000 2010″,”utc_offset”:null,”time_zone”:null,”geo_enabled”:false,”lang”:null,”contributors_enabled”:false,”is_translator”:false,”profile_background_color”:”FFFFFF”,”profile_background_image_url”:”http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png”,”profile_background_image_url_https”:”https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png”,”profile_background_tile”:false,”profile_link_color”:”981CEB”,”profile_sidebar_border_color”:”FFFFFF”,”profile_sidebar_fill_color”:”D4D4D4″,”profile_text_color”:”333333″,”profile_use_background_image”:true,”profile_image_url”:”http:\/\/pbs.twimg.com\/profile_images\/1197464732086587392\/-Q4gjIUl_normal.jpg”,”profile_image_url_https”:”https:\/\/pbs.twimg.com\/profile_images\/1197464732086587392\/-Q4gjIUl_normal.jpg”,”profile_banner_url”:”https:\/\/pbs.twimg.com\/profile_banners\/128487133\/1574332816″,”default_profile”:false,”default_profile_image”:false,”following”:null,”follow_request_sent”:null,”notifications”:null},”geo”:null,”coordinates”:null,”place”:null,”contributors”:null,”is_quote_status”:false,”extended_tweet”:{“full_text”:”[#2019MAMA] Call from #GOT7\n\nThe energy from @GOT7Official is over the top ready for MAMA\ud83e\udd70 They give a little tea about their coming performance referring to how they are seated!\n\n#MAMA #MnetAsianMusicAwards https:\/\/t.co\/tBT7QJgEWr”,”display_text_range”:[0,207],”entities”:{“hashtags”:[{“text”:”2019MAMA”,”indices”:[1,10]},{“text”:”GOT7″,”indices”:[22,27]},{“text”:”MAMA”,”indices”:[180,185]},{“text”:”MnetAsianMusicAwards”,”indices”:[186,207]}],”urls”:[],”user_mentions”:[{“screen_name”:”GOT7Official”,”name”:”GOT7″,”id”:573299587,”id_str”:”573299587″,”indices”:[45,58]}],”symbols”:[],”media”:[{“id”:1200393045457293313,”id_str”:”1200393045457293313″,”indices”:[208,231],”additional_media_info”:{“title”:””,”description”:””,”embeddable”:true,”monetizable”:false},”media_url”:”http:\/\/pbs.twimg.com\/amplify_video_thumb\/1200393045457293313\/img\/zcYPXd9N-1rq0f4o.jpg”,”media_url_https”:”https:\/\/pbs.twimg.com\/amplify_video_thumb\/1200393045457293313\/img\/zcYPXd9N-1rq0f4o.jpg”,”url”:”https:\/\/t.co\/tBT7QJgEWr”,”display_url”:”pic.twitter.com\/tBT7QJgEWr”,”expanded_url”:”https:\/\/twitter.com\/MnetMAMA\/status\/1201735312201773057\/video\/1″,”type”:”video”,”video_info”:{“aspect_ratio”:[9,16],”duration_millis”:58033,”variants”:[{“content_type”:”application\/x-mpegURL”,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/pl\/lkHsp8ZXdDxP8aDa.m3u8?tag=13″},{“bitrate”:632000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/320×568\/-pLWIUhqw8VaFY5X.mp4?tag=13″},{“bitrate”:832000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/360×640\/yz9aMBjNUg-mjeC7.mp4?tag=13″},{“bitrate”:2176000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/720×1280\/Isbx9RDWrZA-yf1f.mp4?tag=13″}]},”sizes”:{“thumb”:{“w”:150,”h”:150,”resize”:”crop”},”small”:{“w”:383,”h”:680,”resize”:”fit”},”large”:{“w”:720,”h”:1280,”resize”:”fit”},”medium”:{“w”:675,”h”:1200,”resize”:”fit”}}}]},”extended_entities”:{“media”:[{“id”:1200393045457293313,”id_str”:”1200393045457293313″,”indices”:[208,231],”additional_media_info”:{“title”:””,”description”:””,”embeddable”:true,”monetizable”:false},”media_url”:”http:\/\/pbs.twimg.com\/amplify_video_thumb\/1200393045457293313\/img\/zcYPXd9N-1rq0f4o.jpg”,”media_url_https”:”https:\/\/pbs.twimg.com\/amplify_video_thumb\/1200393045457293313\/img\/zcYPXd9N-1rq0f4o.jpg”,”url”:”https:\/\/t.co\/tBT7QJgEWr”,”display_url”:”pic.twitter.com\/tBT7QJgEWr”,”expanded_url”:”https:\/\/twitter.com\/MnetMAMA\/status\/1201735312201773057\/video\/1″,”type”:”video”,”video_info”:{“aspect_ratio”:[9,16],”duration_millis”:58033,”variants”:[{“content_type”:”application\/x-mpegURL”,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/pl\/lkHsp8ZXdDxP8aDa.m3u8?tag=13″},{“bitrate”:632000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/320×568\/-pLWIUhqw8VaFY5X.mp4?tag=13″},{“bitrate”:832000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/360×640\/yz9aMBjNUg-mjeC7.mp4?tag=13″},{“bitrate”:2176000,”content_type”:”video\/mp4″,”url”:”https:\/\/video.twimg.com\/amplify_video\/1200393045457293313\/vid\/720×1280\/Isbx9RDWrZA-yf1f.mp4?tag=13″}]},”sizes”:{“thumb”:{“w”:150,”h”:150,”resize”:”crop”},”small”:{“w”:383,”h”:680,”resize”:”fit”},”large”:{“w”:720,”h”:1280,”resize”:”fit”},”medium”:{“w”:675,”h”:1200,”resize”:”fit”}}}]}},”quote_count”:1066,”reply_count”:1014,”retweet_count”:25219,”favorite_count”:44157,”entities”:{“hashtags”:[{“text”:”2019MAMA”,”indices”:[1,10]},{“text”:”GOT7″,”indices”:[22,27]}],”urls”:[{“url”:”https:\/\/t.co\/BujGdLVNv3″,”expanded_url”:”https:\/\/twitter.com\/i\/web\/status\/1201735312201773057″,”display_url”:”twitter.com\/i\/web\/status\/1\u2026″,”indices”:[117,140]}],”user_mentions”:[{“screen_name”:”GOT7Official”,”name”:”GOT7″,”id”:573299587,”id_str”:”573299587″,”indices”:[45,58]}],”symbols”:[]},”favorited”:false,”retweeted”:false,”possibly_sensitive”:false,”filter_level”:”low”,”lang”:”en”},”is_quote_status”:false,”quote_count”:0,”reply_count”:0,”retweet_count”:0,”favorite_count”:0,”entities”:{“hashtags”:[{“text”:”2019MAMA”,”indices”:[15,24]},{“text”:”GOT7″,”indices”:[36,41]}],”urls”:[],”user_mentions”:[{“screen_name”:”MnetMAMA”,”name”:”MAMA(\uc5e0\ub137\uc544\uc2dc\uc548\ubba4\uc9c1\uc5b4\uc6cc\uc988)”,”id”:128487133,”id_str”:”128487133″,”indices”:[3,12]},{“screen_name”:”GOT7Official”,”name”:”GOT7″,”id”:573299587,”id_str”:”573299587″,”indices”:[59,72]}],”symbols”:[]},”favorited”:false,”retweeted”:false,”filter_level”:”low”,”lang”:”en”,”timestamp_ms”:”1575467595405″}
Exception in thread “main” NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{IwL_x4a-TmavamPjAcYgIQ}{localhost}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:352)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:248)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:388)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:391)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:46)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:53)
at elastic.App.insertIntoElastic(App.java:109)
at elastic.App.main(App.java:64)
What is your elasticsearch cluster name? If your cluster name is different than “elasticsearch” then you have to set the cluster name while creating the transport client:
Settings settings = Settings.builder()
.put("cluster.name", "myClusterName").build();
TransportClient client = new PreBuiltTransportClient(settings);