Category Archives: Programming

Elasticsearch Java API – Get Alias List

Elasticsearch Java API - Get Alias List

Elasticsearch Java API – Get Alias List

Elasticsearch Java API - Get Alias List

The following is sample Java program to get the list of aliases in an Elasticsearch instance. Sample Program: package com.report.test; import java.util.ArrayList; import java.util.List; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class SampleProgram{ public static void main(String[] args) { String hostname = “localhost”; String clusterName = “elasticsearch”; Settings… Read More »

Elasticsearch Java API – Get Index List

Elasticsearch Java API - Get Index List

Elasticsearch Java API – Get Index List

Elasticsearch Java API - Get Index List

The following is sample Java program to get the list of indices in an Elasticsearch instance. Sample Program: package com.report.test; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class SampleProgram{ public static void main(String[] args) { String hostname = “localhost”; String clusterName = “elasticsearch”; Settings settings = ImmutableSettings.settingsBuilder().put(“client.transport.sniff”, true).put(“cluster.name”, clusterName).build(); Client esclient… Read More »

Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX

Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX

Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX

Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX

           I faced this issue when I used my web application to send AJAX request to get data from Elasticsearch. The web application was deployed in Apache Tomcat (port 8080 was used). XMLHttpRequest cannot load http://localhost:9200/. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8080’ is therefore not allowed… Read More »

REGEX (Regular Expression) to Remove/Strip HTML Tags in PERL

REGEX (Regular Expression) to Remove or Strip HTML Tags in PERL

REGEX (Regular Expression) to Remove/Strip HTML Tags in PERL

REGEX (Regular Expression) to Remove or Strip HTML Tags in PERL

The following regular expression can be used in Perl progamming language to remove/strip HTML tags in given string. Regular Expression: s/<(?:[^>’”]*|([‘”]).*?\1)*>//ig   Example: my $data ='<script>TEST</script> <img src=”img.jpg”>’; $data =~ s/<(?:[^>'”]*|([‘”]).*?\1)*>//ig; print $data; Output: TEST