2323import org .elasticsearch .client .node .NodeClient ;
2424import org .elasticsearch .common .Strings ;
2525import org .elasticsearch .common .settings .Settings ;
26+ import org .elasticsearch .common .unit .TimeValue ;
2627import org .elasticsearch .common .xcontent .DeprecationHandler ;
2728import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
2829import org .elasticsearch .common .xcontent .ToXContent ;
@@ -61,25 +62,47 @@ public class Job {
6162 public static final boolean DEFAULT_INCLUDE_EXPLANATION = false ;
6263 public static final boolean DEFAULT_INCLUDE_HITS = true ;
6364 public static final boolean DEFAULT_INCLUDE_QUERIES = false ;
65+ public static final boolean DEFAULT_INCLUDE_SEQ_NO_PRIMARY_TERM = false ;
6466 public static final boolean DEFAULT_INCLUDE_SOURCE = true ;
67+ public static final boolean DEFAULT_INCLUDE_VERSION = false ;
6568 public static final int DEFAULT_MAX_DOCS_PER_QUERY = 1000 ;
6669 public static final int DEFAULT_MAX_HOPS = 100 ;
70+ public static final String DEFAULT_MAX_TIME_PER_QUERY = "10s" ;
6771 public static final boolean DEFAULT_PRETTY = false ;
6872 public static final boolean DEFAULT_PROFILE = false ;
6973
74+ // Constants (optional search parameters)
75+ public static Boolean DEFAULT_SEARCH_ALLOW_PARTIAL_SEARCH_RESULTS = null ;
76+ public static Integer DEFAULT_SEARCH_BATCHED_REDUCE_SIZE = null ;
77+ public static Integer DEFAULT_SEARCH_MAX_CONCURRENT_SHARD_REQUESTS = null ;
78+ public static Integer DEFAULT_SEARCH_PRE_FILTER_SHARD_SIZE = null ;
79+ public static String DEFAULT_SEARCH_PREFERENCE = null ;
80+ public static Boolean DEFAULT_SEARCH_REQUEST_CACHE = null ;
81+
7082 // Job configuration
7183 private Input input ;
7284 private boolean includeAttributes = DEFAULT_INCLUDE_ATTRIBUTES ;
7385 private boolean includeErrorTrace = DEFAULT_INCLUDE_ERROR_TRACE ;
7486 private boolean includeExplanation = DEFAULT_INCLUDE_EXPLANATION ;
7587 private boolean includeHits = DEFAULT_INCLUDE_HITS ;
7688 private boolean includeQueries = DEFAULT_INCLUDE_QUERIES ;
89+ private boolean includeSeqNoPrimaryTerm = DEFAULT_INCLUDE_SEQ_NO_PRIMARY_TERM ;
7790 private boolean includeSource = DEFAULT_INCLUDE_SOURCE ;
91+ private boolean includeVersion = DEFAULT_INCLUDE_VERSION ;
7892 private int maxDocsPerQuery = DEFAULT_MAX_DOCS_PER_QUERY ;
7993 private int maxHops = DEFAULT_MAX_HOPS ;
94+ private String maxTimePerQuery = DEFAULT_MAX_TIME_PER_QUERY ;
8095 private boolean pretty = DEFAULT_PRETTY ;
8196 private boolean profile = DEFAULT_PROFILE ;
8297
98+ // Job configuration (optional search parameters)
99+ private Boolean searchAllowPartialSearchResults = DEFAULT_SEARCH_ALLOW_PARTIAL_SEARCH_RESULTS ;
100+ private Integer searchBatchedReduceSize = DEFAULT_SEARCH_BATCHED_REDUCE_SIZE ;
101+ private Integer searchMaxConcurrentShardRequests = DEFAULT_SEARCH_MAX_CONCURRENT_SHARD_REQUESTS ;
102+ private Integer searchPreFilterShardSize = DEFAULT_SEARCH_PRE_FILTER_SHARD_SIZE ;
103+ private String searchPreference = DEFAULT_SEARCH_PREFERENCE ;
104+ private Boolean searchRequestCache = DEFAULT_SEARCH_REQUEST_CACHE ;
105+
83106 // Job state
84107 private Map <String , Attribute > attributes = new TreeMap <>();
85108 private NodeClient client ;
@@ -581,6 +604,12 @@ public void includeQueries(boolean includeQueries) {
581604 this .includeQueries = includeQueries ;
582605 }
583606
607+ public Boolean includeSeqNoPrimaryTerm () {
608+ return this .includeSeqNoPrimaryTerm ;
609+ }
610+
611+ public void includeSeqNoPrimaryTerm (Boolean includeSeqNoPrimaryTerm ) { this .includeSeqNoPrimaryTerm = includeSeqNoPrimaryTerm ; }
612+
584613 public boolean includeSource () {
585614 return this .includeSource ;
586615 }
@@ -589,13 +618,9 @@ public void includeSource(boolean includeSource) {
589618 this .includeSource = includeSource ;
590619 }
591620
592- public int maxHops () {
593- return this .maxHops ;
594- }
621+ public Boolean includeVersion () { return this .includeVersion ; }
595622
596- public void maxHops (int maxHops ) {
597- this .maxHops = maxHops ;
598- }
623+ public void includeVersion (Boolean includeVersion ) { this .includeVersion = includeVersion ; }
599624
600625 public int maxDocsPerQuery () {
601626 return this .maxDocsPerQuery ;
@@ -605,6 +630,18 @@ public void maxDocsPerQuery(int maxDocsPerQuery) {
605630 this .maxDocsPerQuery = maxDocsPerQuery ;
606631 }
607632
633+ public int maxHops () {
634+ return this .maxHops ;
635+ }
636+
637+ public void maxHops (int maxHops ) {
638+ this .maxHops = maxHops ;
639+ }
640+
641+ public String maxTimePerQuery () { return this .maxTimePerQuery ; }
642+
643+ public void maxTimePerQuery (String maxTimePerQuery ) { this .maxTimePerQuery = maxTimePerQuery ; }
644+
608645 public boolean pretty () {
609646 return this .pretty ;
610647 }
@@ -621,6 +658,41 @@ public void profile(Boolean profile) {
621658 this .profile = profile ;
622659 }
623660
661+ public Boolean searchAllowPartialSearchResults () {
662+ return this .searchAllowPartialSearchResults ;
663+ }
664+
665+ public void searchAllowPartialSearchResults (Boolean searchAllowPartialSearchResults ) { this .searchAllowPartialSearchResults = searchAllowPartialSearchResults ; }
666+
667+ public Integer searchBatchedReduceSize () {
668+ return this .searchBatchedReduceSize ;
669+ }
670+
671+ public void searchBatchedReduceSize (Integer searchBatchedReduceSize ) { this .searchBatchedReduceSize = searchBatchedReduceSize ; }
672+
673+ public Integer searchMaxConcurrentShardRequests () {
674+ return this .searchMaxConcurrentShardRequests ;
675+ }
676+
677+ public void searchMaxConcurrentShardRequests (Integer searchMaxConcurrentShardRequests ) { this .searchMaxConcurrentShardRequests = searchMaxConcurrentShardRequests ; }
678+
679+ public Integer searchPreFilterShardSize () {
680+ return this .searchPreFilterShardSize ;
681+ }
682+
683+ public void searchPreFilterShardSize (Integer searchPreFilterShardSize ) { this .searchPreFilterShardSize = searchPreFilterShardSize ; }
684+
685+ public String searchPreference () {
686+ return this .searchPreference ;
687+ }
688+
689+ public void searchPreference (String searchPreference ) { this .searchPreference = searchPreference ; }
690+ public Boolean searchRequestCache () {
691+ return this .searchRequestCache ;
692+ }
693+
694+ public void searchRequestCache (Boolean searchRequestCache ) { this .searchRequestCache = searchRequestCache ; }
695+
624696 public Input input () {
625697 return this .input ;
626698 }
@@ -653,7 +725,22 @@ private SearchResponse search(String indexName, String query) throws IOException
653725 searchSourceBuilder .parseXContent (parser );
654726 }
655727 SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder (client , SearchAction .INSTANCE );
656- return searchRequestBuilder .setIndices (indexName ).setSource (searchSourceBuilder ).execute ().actionGet ();
728+ searchRequestBuilder .setIndices (indexName ).setSource (searchSourceBuilder );
729+ if (this .searchAllowPartialSearchResults != null )
730+ searchRequestBuilder .setAllowPartialSearchResults (this .searchAllowPartialSearchResults );
731+ if (this .searchBatchedReduceSize != null )
732+ searchRequestBuilder .setBatchedReduceSize (this .searchBatchedReduceSize );
733+ if (this .searchMaxConcurrentShardRequests != null )
734+ searchRequestBuilder .setMaxConcurrentShardRequests (this .searchMaxConcurrentShardRequests );
735+ if (this .searchPreFilterShardSize != null )
736+ searchRequestBuilder .setPreFilterShardSize (this .searchPreFilterShardSize );
737+ if (this .searchPreference != null )
738+ searchRequestBuilder .setPreference (this .searchPreference );
739+ if (this .searchRequestCache != null )
740+ searchRequestBuilder .setRequestCache (this .searchRequestCache );
741+ if (this .maxTimePerQuery != null )
742+ searchRequestBuilder .setTimeout (TimeValue .parseTimeValue (this .maxTimePerQuery , "timeout" ));
743+ return searchRequestBuilder .execute ().actionGet ();
657744 }
658745
659746 /**
@@ -1018,6 +1105,10 @@ else if (!resolversClause.isEmpty())
10181105 // Construct the "profile" clause.
10191106 if (this .profile )
10201107 topLevelClauses .add ("\" profile\" :true" );
1108+ if (this .includeSeqNoPrimaryTerm )
1109+ topLevelClauses .add ("\" seq_no_primary_term\" :true" );
1110+ if (this .includeVersion )
1111+ topLevelClauses .add ("\" version\" :true" );
10211112
10221113 // Construct the final query.
10231114 query = "{" + String .join ("," , topLevelClauses ) + "}" ;
0 commit comments