Category Archives: Programming

Elasticsearch Java API – Get Field List for a given Index and Type

Elasticsearch Java API - Get Field List for a given Index and Type

Elasticsearch Java API – Get Field List for a given Index and Type

Elasticsearch Java API - Get Field List for a given Index and Type

The following is sample Java program to get the list of fields for a given index and type name in an Elasticsearch instance. Sample Program: package com.report.test; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class SampleProgram{ public… Read More »

Elasticsearch Java API – Get Type List from given Index

Elasticsearch Java API - Get Type List from given Index

Elasticsearch Java API – Get Type List from given Index

Elasticsearch Java API - Get Type List from given Index

The following is sample Java program to get the list of type for a given index name in an Elasticsearch instance. Sample Program: package com.report.test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; public class SampleProgram{ public static… Read More »

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 »