5
votes

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

1 Answers

7
votes

Try using fetchSource() like this:

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