# Java Client вопрос по самому простому клиенту

**URL:** <https://discuss.elastic.co/t/java-client/57927>\
**Category:** Вопросы на русском языке\
**Created:** [August 12, 2016, 1:34pm UTC](https://discuss.elastic.co/t/java-client/57927 "2016-08-12T13:34:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 12, 2016, 1:34pm UTC](https://discuss.elastic.co/t/java-client/57927/1 "2016-08-12T13:34:12Z")

</div>

И снова у меня вопрос. Теперь пытаюсь из Java достучаться до сервера.  
Сервер точно поднят - из сенса запросы возвращает.

Компилятор никаких ошибок не показывает.  
Мавен тоже ни на что не ругается.  
JavaCode:

```
public class ElasticStore {

    // on startup

    public static void main(String[] args) throws IOException {
        Settings settings = Settings.settingsBuilder()
                .put("cluster.name", "test-application").build();

        Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("http://192.168.200.43"), 9300));

        IndexResponse response = client.prepareIndex("rustest", "type1", "1")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("body", "kimchy")
                        .endObject()
                )
                .get();

        // on shutdown

        client.close();
    }
}

```

Падает с ошибкой  
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

На форумах советуют установить 18ую гуаву.

```
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>

```

Но мне и это не помогло.

Я хочу проапдейтить индекс на своем тестовом сервере из Java приложения.

Из node.js все работает... А вот Java уже второй день никак не подниму.

Такое ощущение что падает на

`NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();`

в методе public TransportClient build() у TransportClient . Но что ему не нравится пока не понимаю...

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 12, 2016, 1:52pm UTC](https://discuss.elastic.co/t/java-client/57927/2 "2016-08-12T13:52:13Z")

</div>

Секцию `dependencies` из pomа покажите?

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 12, 2016, 2:16pm UTC](https://discuss.elastic.co/t/java-client/57927/3 "2016-08-12T14:16:39Z")

</div>

В parent у эластика тоже гуава 18, но на всякий случай еще и в депенденси добавил. Не помогло.

```
<dependencies>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-core</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.3.3</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
</dependencies>
```

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 12, 2016, 3:02pm UTC](https://discuss.elastic.co/t/java-client/57927/4 "2016-08-12T15:02:12Z")

</div>

Сейчас пытаюсь обойти проблему как тут показано [https://www.elastic.co/blog/to-shade-or-not-to-shade](https://www.elastic.co/blog/to-shade-or-not-to-shade)

Пока что с шилдом вожусь.

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 12, 2016, 4:06pm UTC](https://discuss.elastic.co/t/java-client/57927/5 "2016-08-12T16:06:50Z")

</div>

Пациенту все еще плохо...

mvn clear install  
INFO] Including com.google.guava:guava:jar:18.0 in the shaded jar.

Вот код моей новой чудо либы.

\<?xml version="1.0" encoding="UTF-8"?\>

4.0.0

```
<groupId>my.elasticsearch.test</groupId>
<artifactId>es-shaded</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <elasticsearch.version>2.3.3</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>shield</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
</dependencies>
<repositories>

    <repository>
        <id>elasticsearch-releases</id>
        <url>http://maven.elasticsearch.org/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <relocations>
                            <relocation>
                                <pattern>org.joda</pattern>
                                <shadedPattern>${project.groupId}.shaded..joda</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>com.google.common</pattern>
                                <shadedPattern>${project.groupId}.shaded.google.common</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.apache.lucene</pattern>
                                <shadedPattern>${project.groupId}.shaded.lucene_5_5_0</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

```

Ее я затем импортирую.  
Запускаю. И дальше уже падаю на компиляторе.

```
Error:(41, 25) java: cannot access org.apache.lucene.util.BytesRef
  class file for org.apache.lucene.util.BytesRef not found
```

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 13, 2016, 12:11am UTC](https://discuss.elastic.co/t/java-client/57927/6 "2016-08-13T00:11:10Z")

</div>

> [@whispersofdew](#):
>
> Error:(41, 25) java: cannot access org.apache.lucene.util.BytesRef  
> class file for org.apache.lucene.util.BytesRef not found

Если вы lucene зашейдили, может тогда надо `my.elasticsearch.test.org.apache.lucene.util.BytesRef` использовать?

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 15, 2016, 7:21am UTC](https://discuss.elastic.co/t/java-client/57927/7 "2016-08-15T07:21:58Z")

</div>

Я правильно понимаю, что для этого мне надо залезть в pom.xml elasticsearch и подменить в нем все ссылки на lucene? Или есть другой более человеколюбивый путь?

Может быть я изначально иду в неверном направлении?

У меня задача - просто чтоб заработало. Чтоб тот текст, который я с помощью apache tika достаю из word - я мог бы отправить в elastic и проиндексировать...  
Без нагрузок и прочего. Самый самый простой сценарий.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 15, 2016, 2:55pm UTC](https://discuss.elastic.co/t/java-client/57927/8 "2016-08-15T14:55:02Z")

</div>

Вы не могли бы показать на примере, что у вас не работает? Вот проект: [https://github.com/imotov/es-shaded](https://github.com/imotov/es-shaded), поправьте его так, чтобы оно перестало работать и откройте PR. Так, наверное, проще будет.

Я тестировал так - запустил кластер с именем `elasticsearch-imotov` и потом

```auto
$ git clone https://github.com/imotov/es-shaded.git
$ cd es-shaded
$ mvn package
$ java -classpath ./target/es-shaded-1.0-SNAPSHOT.jar org.motovs.tests.App

```

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [August 16, 2016, 8:21am UTC](https://discuss.elastic.co/t/java-client/57927/9 "2016-08-16T08:21:13Z")

</div>

> [@Igor\_Motov](#):
>
> git clone [GitHub - imotov/es-shaded: Temporary example](https://github.com/imotov/es-shaded.git)

Ваш пример рабочий!!!  
С первого раза все запустилось.

Видимо зря я отдельную библиотеку собирал. Надо было шейдить в этом же проекте.  
Короче говоря как я и думал косяк был в том что я не до конца понял спеку... Сейчас буду искать что делал не так.

Спасибо большое! В который раз выручаете!!!

Я бы ваш пример в мануалы включил )))

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:46pm UTC](https://discuss.elastic.co/t/java-client/57927/10 "2017-07-06T13:46:25Z")

</div>


