9
9
import java .util .Map ;
10
10
import java .util .concurrent .TimeUnit ;
11
11
import java .util .function .Function ;
12
+ import java .util .Objects ;
12
13
13
14
import org .apache .logging .log4j .LogManager ;
14
15
import org .apache .logging .log4j .Logger ;
28
29
import org .elasticsearch .client .Client ;
29
30
import org .elasticsearch .cluster .metadata .IndexAbstraction ;
30
31
import org .elasticsearch .cluster .metadata .IndexMetadata ;
32
+ import org .elasticsearch .cluster .metadata .MappingMetadata ;
31
33
import org .elasticsearch .cluster .metadata .Metadata ;
32
34
import org .elasticsearch .cluster .service .ClusterService ;
33
35
import org .elasticsearch .common .component .AbstractLifecycleComponent ;
39
41
import org .elasticsearch .common .settings .Setting ;
40
42
import org .elasticsearch .common .settings .Setting .Property ;
41
43
import org .elasticsearch .common .settings .Settings ;
42
- import org .elasticsearch .common .unit .TimeValue ;
43
44
import org .elasticsearch .common .util .concurrent .ThreadContext ;
45
+ import org .elasticsearch .core .TimeValue ;
44
46
import org .elasticsearch .script .Script ;
45
47
import org .elasticsearch .script .ScriptService ;
46
48
import org .elasticsearch .script .ScriptType ;
49
51
import org .elasticsearch .search .aggregations .InternalAggregations ;
50
52
import org .elasticsearch .search .builder .SearchSourceBuilder ;
51
53
import org .elasticsearch .search .internal .InternalSearchResponse ;
52
- import org .elasticsearch .search .profile .SearchProfileShardResults ;
54
+ import org .elasticsearch .search .profile .SearchProfileResults ;
53
55
import org .elasticsearch .search .suggest .Suggest ;
54
56
import org .elasticsearch .threadpool .ThreadPool ;
55
57
@@ -254,11 +256,15 @@ public ScriptInfo getScriptInfo(final String index) {
254
256
return ScriptInfo .NO_SCRIPT_INFO ;
255
257
}
256
258
257
- final ScriptInfo [] scriptInfos = indexAbstraction .getIndices ().stream ().map (md -> md .getSettings ())
258
- .filter (s -> SETTING_INDEX_DYNARANK_LANG .get (s ).length () > 0 )
259
- .map (settings -> new ScriptInfo (SETTING_INDEX_DYNARANK_SCRIPT .get (settings ),
260
- SETTING_INDEX_DYNARANK_LANG .get (settings ), SETTING_INDEX_DYNARANK_TYPE .get (settings ),
261
- SETTING_INDEX_DYNARANK_PARAMS .get (settings ), SETTING_INDEX_DYNARANK_REORDER_SIZE .get (settings ), SETTING_INDEX_DYNARANK_KEEP_TOPN .get (settings )))
259
+ final ScriptInfo [] scriptInfos = indexAbstraction .getIndices ().stream ()
260
+ .map (metaData ::index )
261
+ .filter (idx -> SETTING_INDEX_DYNARANK_LANG .get (idx .getSettings ()).length () > 0 )
262
+ .map (idx ->
263
+ new ScriptInfo (SETTING_INDEX_DYNARANK_SCRIPT .get (idx .getSettings ()), SETTING_INDEX_DYNARANK_LANG .get (idx .getSettings ()),
264
+ SETTING_INDEX_DYNARANK_TYPE .get (idx .getSettings ()), SETTING_INDEX_DYNARANK_PARAMS .get (idx .getSettings ()),
265
+ SETTING_INDEX_DYNARANK_REORDER_SIZE .get (idx .getSettings ()), SETTING_INDEX_DYNARANK_KEEP_TOPN .get (idx .getSettings ()),
266
+ idx .mapping ())
267
+ )
262
268
.toArray (n -> new ScriptInfo [n ]);
263
269
264
270
if (scriptInfos .length == 0 ) {
@@ -337,7 +343,7 @@ public void onResponse(final Response response) {
337
343
final Suggest suggest = in .readBoolean () ? new Suggest (in ) : null ;
338
344
final boolean timedOut = in .readBoolean ();
339
345
final Boolean terminatedEarly = in .readOptionalBoolean ();
340
- final SearchProfileShardResults profileResults = in .readOptionalWriteable (SearchProfileShardResults ::new );
346
+ final SearchProfileResults profileResults = in .readOptionalWriteable (SearchProfileResults ::new );
341
347
final int numReducePhases = in .readVInt ();
342
348
343
349
final SearchResponseSections internalResponse = new InternalSearchResponse (newHits , aggregations , suggest ,
@@ -490,7 +496,7 @@ public static class ScriptInfo {
490
496
// nothing
491
497
}
492
498
493
- ScriptInfo (final String script , final String lang , final String scriptType , final Settings settings , final int reorderSize ,final int keepTopN ) {
499
+ ScriptInfo (final String script , final String lang , final String scriptType , final Settings settings , final int reorderSize , final int keepTopN , final MappingMetadata mappingMetadata ) {
494
500
this .script = script ;
495
501
this .lang = lang ;
496
502
this .reorderSize = reorderSize ;
@@ -500,6 +506,7 @@ public static class ScriptInfo {
500
506
final List <String > list = settings .getAsList (name );
501
507
this .settings .put (name , list .toArray (new String [list .size ()]));
502
508
}
509
+ this .settings .put ("source_as_map" , mappingMetadata .getSourceAsMap ());
503
510
if ("STORED" .equalsIgnoreCase (scriptType )) {
504
511
this .scriptType = ScriptType .STORED ;
505
512
} else {
@@ -577,7 +584,8 @@ public void run() {
577
584
578
585
final ScriptInfo scriptInfo = new ScriptInfo (script , SETTING_INDEX_DYNARANK_LANG .get (indexSettings ),
579
586
SETTING_INDEX_DYNARANK_TYPE .get (indexSettings ), SETTING_INDEX_DYNARANK_PARAMS .get (indexSettings ),
580
- SETTING_INDEX_DYNARANK_REORDER_SIZE .get (indexSettings ), SETTING_INDEX_DYNARANK_KEEP_TOPN .get (indexSettings ));
587
+ SETTING_INDEX_DYNARANK_REORDER_SIZE .get (indexSettings ), SETTING_INDEX_DYNARANK_KEEP_TOPN .get (indexSettings ),
588
+ indexMD .mapping ());
581
589
if (logger .isDebugEnabled ()) {
582
590
logger .debug ("Reload cache for {} => {}" , index , scriptInfo );
583
591
}
0 commit comments