Elasticsearch - get source field data with java api

﹥>﹥吖頭↗ 提交于 2019-12-10 13:45:13

问题


I'm using elastic search with jest (as java client). I need some fields that is in nested document and since cannot get nested fields as pair, I need '_source' to get them.

Here is previous question to get them in ES query[ Link ], and It works well.

BUT cannot convert its query as jest code. Below is my try.

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query( 
            query
        )
        .fields(      // need _source but no method.
          "oid", 
          "_source.events.activityoid", 
          "_source.events.worktime");

回答1:


Try using fetchSource() like this:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
    .query(query)
    .fetchSource(new String[] {
      "oid", 
      "events.activityoid", 
      "events.worktime"
    }, null);


来源:https://stackoverflow.com/questions/38654281/elasticsearch-get-source-field-data-with-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!