简体   繁体   中英

Elasticsearch Java API from 2.x to 5.x issues

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
  2. SearchRequestBuilder.setNoFields is also removed. Which would be the alternative?
  3. 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.

When in doubt, go to the source

  1. use setFetchSource(String[] includes, String[] excludes) instead
  2. use setFetchSource(false) instead
  3. if you need to execute this script for each document, you can use addScriptField()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM