Open HemaAnusha opened 9 years ago
You can not run the Knapsack plugin at transport client side. It must run at server side in a node being part of the cluster.
Hi, Thanks for your response, but When I used to run with the Node client (the following code).
package com.knapsack;
import java.io.File; import java.io.FileReader; import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.xbib.elasticsearch.action.knapsack.exp.KnapsackExportRequest; import org.xbib.elasticsearch.action.knapsack.exp.KnapsackExportRequestBuilder; import org.xbib.elasticsearch.action.knapsack.imp.KnapsackImportRequest;
public class KnapSackImport {
private static Client client = null;
private static Settings settings=null;
public static Client getClient()
{
settings=ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build();
Node node = NodeBuilder.nodeBuilder().settings(settings).node();
client = node.client();
return client;
}
public static void main(String args[]) throws IOException, ParseException
{
KnapsackImportRequest imp=new KnapsackImportRequest();
String settings=imp.getIndexSettings("sayt");
CreateIndexRequestBuilder createIndexRequestBuilder=getClient().admin().indices().prepareCreate("sayt1");
System.out.println(createIndexRequestBuilder);
imp.addIndexSettings("sayt1", settings);
}
}
Am getting the Exception as:
Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_4_10_1
at org.elasticsearch.Version.
May I know why am getting this exception? and how to solve this
And May I know why we should not use Transport Client?
You are using a wrong Elasticsearch / Knapsack version combination.
May I know Which versions combination I have to use?
Knapsack uses indexed data from cluster nodes, it is an internal export/import cluster service. Because TransportClient does not hold any cluster service, this combination is not possible.
The correct ones from the README of course. Example: Elasticsearch 1.5.2 with Knapsack 1.5.2.0
Hi, I have changed the knapsack jar to 1.4.0.0 as am using Elasticsearch1.4.0 and then I have tried,
package com.knapsack;
import java.io.IOException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.client.Client; import org.elasticsearch.node.Node; import static org.elasticsearch.node.NodeBuilder.*; import org.json.simple.parser.ParseException; import org.xbib.elasticsearch.action.knapsack.imp.KnapsackImportRequest;
public class KnapSackImport {
private static Client client = null;
public static Client getClient()
{
Node node = nodeBuilder().clusterName("elasticsearch").node();
client = node.client();
return client;
}
public static void main(String args[]) throws IOException, ParseException
{
KnapsackImportRequest imp=new KnapsackImportRequest();
String settings=imp.getIndexSettings("sayt");
CreateIndexRequestBuilder createIndexRequestBuilder=getClient().admin().indices().prepareCreate("sayt1");
System.out.println(createIndexRequestBuilder);
imp.addIndexSettings("sayt1", settings);
}
}
Even am getting the error as:
Exception in thread "main" java.lang.NoSuchFieldError: V_1_4_2
at org.elasticsearch.shield.ShieldVersion.
Is this problem related to knapsack or any other and may I know the relevant solution
Shield is not supported, sorry. It is not open source.
So is there any solution for this or else do I need to use knapsack in other way?
Sure, you have to disable Shield or ask Shield support for a solution.
Okay Thank you So much..
Hi, As you said I disabled the shield as shown, public class KnapSackImport {
private static Client client = null;
public static Client getClient()
{
Node node = nodeBuilder().settings(ImmutableSettings.builder().put("shield.enabled",false)).clusterName("elasticsearch").node();
client = node.client();
return client;
}
public static void main(String args[]) throws IOException, ParseException
{
KnapsackImportRequest imp=new KnapsackImportRequest();
String settings=imp.getIndexSettings("sayt");
CreateIndexRequestBuilder createIndexRequestBuilder=getClient().admin().indices().prepareCreate("sayt1");
System.out.println(createIndexRequestBuilder);
imp.addIndexSettings("sayt1", settings);
}
}
But am getting again the exception as: Exception in thread "main" org.elasticsearch.common.inject.CreationException: Guice creation errors:
1) A binding to org.xbib.elasticsearch.knapsack.KnapsackService was already configured at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25). at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25)
1 error
at org.elasticsearch.common.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:344)
at org.elasticsearch.common.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:151)
at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:102)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:59)
at org.elasticsearch.node.internal.InternalNode.
May I know the reason and solution to this?
You seem to have an error in your node setup, maybe you initialized twice. The getClient()
method makes no sense, there is a node created (and not started) for each client?
This simple node test works: https://github.com/jprante/elasticsearch-knapsack/commit/c20195d208918a8311418aba2eed971788fd2edc
Hi Jorg, The following changes I have done using that simple node test:
public class KnapSackImport {
private static Client client = null;
static Node node=null;
public static void main(String args[]) throws IOException, ParseException
{
Settings settings = settingsBuilder()
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
.put("gateway.type", "none")
.put("index.store.type", "memory")
.put("http.enabled", false)
.put("discovery.zen.multicast.enabled", false).put("shield.enabled", false)
.build();
node = nodeBuilder().settings(settings).build();
node.start();
client = node.client();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
if(client!=null)
{
System.out.println("client created");
}
else
System.out.println("not");
KnapsackImportRequest imp=new KnapsackImportRequest();
String settingsSayt=imp.getIndexSettings("sayt");
CreateIndexRequestBuilder createIndexRequestBuilder=client.admin().indices().prepareCreate("sayt1");
System.out.println(createIndexRequestBuilder);
imp.addIndexSettings("sayt1", settingsSayt);
node.stop();
}
}
Again am getting the exception as:
Exception in thread "main" org.elasticsearch.common.inject.CreationException: Guice creation errors:
1) A binding to org.xbib.elasticsearch.knapsack.KnapsackService was already configured at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25). at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25)
1 error
at org.elasticsearch.common.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:344)
at org.elasticsearch.common.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:151)
at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:102)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:59)
at org.elasticsearch.node.internal.InternalNode.
Where am getting the problem at node , May I know solution to this..
Hi, Am using elasticsearch-knapsack plugin for update settings and for few other actions but am unable to start it , I just started using normal client creation as:
public class KnapSackImport {
private static Client client = null;
@Inject public static Client getClient() { Client client = new TransportClient() .addTransportAddress(new InetSocketTransportAddress("192.168.1.59", 9300)); if(client!=null) { System.out.println("client"); } return client; }
public static void main(String args[]) {
}
}
So when am running this am getting :
Exception in thread "main" org.elasticsearch.common.inject.CreationException: Guice creation errors:
1) No implementation for org.elasticsearch.cluster.ClusterService was bound. while locating org.elasticsearch.cluster.ClusterService for parameter 1 at org.xbib.elasticsearch.knapsack.KnapsackService.(Unknown Source) at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25)
2) A binding to org.xbib.elasticsearch.knapsack.KnapsackService was already configured at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25). at org.xbib.elasticsearch.knapsack.KnapsackModule.configure(KnapsackModule.java:25)
2 errors at org.elasticsearch.common.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:344) at org.elasticsearch.common.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:151) at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:102) at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93) at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70) at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:59) at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:187) at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:115) at com.knapsack.KnapSackImport.getClient(KnapSackImport.java:21) at com.knapsack.KnapSackImport.main(KnapSackImport.java:33)
Can anyone trace this and tell me how to proceed with this ..