简体   繁体   English

从2.x到5.x的Elasticsearch Java API问题

[英]Elasticsearch Java API from 2.x to 5.x issues

I've updated to elasticsearch java library version 5.2.0. 我已经更新到Elasticsearch Java库版本5.2.0。

In 2.x, 在2.x版本中,

  1. I was using SearchRequestBuilder.addField() in order to add a field to the search request. 我正在使用SearchRequestBuilder.addField()以便向搜索请求中添加一个字段。 Nevertheless, It seems to be replaced. 尽管如此,它似乎已被替换。 I've written the available methods intellisense is showing me. 我已经编写了intellisense向我展示的可用方法。 Which of them do I need to pick? 我需要选哪个?
    • addDocValueField
    • addFieldDataField
    • addScriptField
    • addStoredField
    • storedFields
    • fields
  2. SearchRequestBuilder.setNoFields is also removed. SearchRequestBuilder.setNoFields也将被删除。 Which would be the alternative? 哪个可以替代?
  3. Currently, I'm calling scripts from Java using this code. 目前,我正在使用此代码从Java调用脚本。 Is there any more elegant way to call it in 5.x Java API? 在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. 如您所见,我将field设置为脚本参数。 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 使用setFetchSource(String[] includes, String[] excludes)
  2. use setFetchSource(false) instead 使用setFetchSource(false)代替
  3. if you need to execute this script for each document, you can use addScriptField() 如果需要为每个文档执行此脚本,则可以使用addScriptField()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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