5

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");
Machavity
  • 30,841
  • 27
  • 92
  • 100
J.Done
  • 2,783
  • 9
  • 31
  • 58

1 Answers1

7

Try using fetchSource() like this:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
    .query(query)
    .fetchSource(new String[] {
      "oid", 
      "events.activityoid", 
      "events.worktime"
    }, null);
Val
  • 207,596
  • 13
  • 358
  • 360