# Several issues on Java API 5.x

**URL:** <https://discuss.elastic.co/t/several-issues-on-java-api-5-x/75867>\
**Category:** Elasticsearch\
**Created:** [February 21, 2017, 11:32am UTC](https://discuss.elastic.co/t/several-issues-on-java-api-5-x/75867 "2017-02-21T11:32:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [February 21, 2017, 11:32am UTC](https://discuss.elastic.co/t/several-issues-on-java-api-5-x/75867/1 "2017-02-21T11:32:10Z")

</div>

I've updated to elasticsearch java library version 5.2.0.

In 2.x,

1. I was using `SearchRequestBuilder.addField()` in order to add a field to the search request. Nevertheless, It seems to be replaced. I've written the available methods intellisense is showing me. Which of them do I need to pick?

- `addDocValueField`
- `addFieldDataField`
- `addScriptField`
- `addStoredField`
- `storedFields`
- `fields`

1. `SearchRequestBuilder.setNoFields` is also removed. Which would be the alternative?
2. Currently, I'm calling scripts from Java using this code. Is there any more elegant way to call it in 5.x Java API?

Code:

```
return AggregationBuilders
    .terms(this.getName())
    .field(this.getName())
    .script(new Script(
        ScriptType.FILE,
        "painless",
        "year",
        ImmutableMap.of("field", this.getName())
    )
);

```

As you can see I setting `field` as script parameter. Nevertheless, I don't quite understand how to get it from script code.

Thanks.

---

<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:** [March 21, 2017, 11:32am UTC](https://discuss.elastic.co/t/several-issues-on-java-api-5-x/75867/2 "2017-03-21T11:32:16Z")

</div>

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