# Index Failure exception returns null JAVA API

**URL:** <https://discuss.elastic.co/t/index-failure-exception-returns-null-java-api/109404>\
**Category:** Elasticsearch\
**Created:** [November 28, 2017, 1:46pm UTC](https://discuss.elastic.co/t/index-failure-exception-returns-null-java-api/109404 "2017-11-28T13:46:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guediagael](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@guediagael](https://discuss.elastic.co/u/guediagael)\
**Post date:** [November 28, 2017, 1:46pm UTC](https://discuss.elastic.co/t/index-failure-exception-returns-null-java-api/109404/1 "2017-11-28T13:46:10Z")

</div>

Hello I'm trying to build an index using elasticsearch java api with java restHighLevelClient, but for some reasons I have an and index failure exception which returns `null`.

I'll like to know the reason so that I can improve the input data at least.  
Thank in advance for the answer.  
P.S: the code is below

```
 private void index(String id,IndexRequest indexRequest){
        restHighLevelClient.indexAsync(indexRequest, new ActionListener<IndexResponse>() {
            @Override
            public void onResponse(IndexResponse indexResponse) {
                successFullIndex++;
                System.out.println("response status: "+ indexResponse.status().toString()+", response: "+ indexResponse.toString());
            }
            @Override
            public void onFailure(Exception e) {
                unsuccessfullIndex++;
                String message = id +" "+e.getMessage();
                System.out.println("index response exception from : " +message);
                try {
                    FileWriter fileWriter = new FileWriter("indexErrors.txt",true);
                    fileWriter.write(message+ "\n");
                    fileWriter.flush();
                    fileWriter.close();

                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        });

    }
```

---

<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:** [December 26, 2017, 1:46pm UTC](https://discuss.elastic.co/t/index-failure-exception-returns-null-java-api/109404/2 "2017-12-26T13:46:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
