-
Notifications
You must be signed in to change notification settings - Fork 242
/
ElasticsearchIndexManager.java
715 lines (594 loc) · 23.8 KB
/
ElasticsearchIndexManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.backend.elasticsearch.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.similarities.Similarity;
import org.hibernate.search.analyzer.impl.AnalyzerReference;
import org.hibernate.search.analyzer.impl.RemoteAnalyzer;
import org.hibernate.search.analyzer.impl.RemoteAnalyzerProvider;
import org.hibernate.search.analyzer.impl.RemoteAnalyzerReference;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.backend.BackendFactory;
import org.hibernate.search.backend.IndexingMonitor;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.OptimizeLuceneWork;
import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchEnvironment;
import org.hibernate.search.backend.elasticsearch.cfg.IndexManagementStrategy;
import org.hibernate.search.backend.elasticsearch.client.impl.JestClient;
import org.hibernate.search.backend.elasticsearch.logging.impl.Log;
import org.hibernate.search.backend.elasticsearch.spi.ElasticsearchIndexManagerType;
import org.hibernate.search.backend.spi.BackendQueueProcessor;
import org.hibernate.search.cfg.Environment;
import org.hibernate.search.engine.integration.impl.ExtendedSearchIntegrator;
import org.hibernate.search.engine.metadata.impl.BridgeDefinedField;
import org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata;
import org.hibernate.search.engine.metadata.impl.FacetMetadata;
import org.hibernate.search.engine.metadata.impl.PropertyMetadata;
import org.hibernate.search.engine.metadata.impl.TypeMetadata;
import org.hibernate.search.engine.service.spi.ServiceManager;
import org.hibernate.search.engine.service.spi.ServiceReference;
import org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity;
import org.hibernate.search.engine.spi.EntityIndexBinding;
import org.hibernate.search.exception.AssertionFailure;
import org.hibernate.search.exception.SearchException;
import org.hibernate.search.indexes.serialization.impl.LuceneWorkSerializerImpl;
import org.hibernate.search.indexes.serialization.spi.LuceneWorkSerializer;
import org.hibernate.search.indexes.serialization.spi.SerializationProvider;
import org.hibernate.search.indexes.spi.IndexManager;
import org.hibernate.search.indexes.spi.IndexManagerType;
import org.hibernate.search.indexes.spi.ReaderProvider;
import org.hibernate.search.metadata.NumericFieldSettingsDescriptor.NumericEncodingType;
import org.hibernate.search.spatial.impl.SpatialHelper;
import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.util.configuration.impl.ConfigurationParseHelper;
import org.hibernate.search.util.logging.impl.LoggerFactory;
import com.google.gson.JsonObject;
import io.searchbox.client.JestResult;
import io.searchbox.cluster.Health;
import io.searchbox.cluster.Health.Builder;
import io.searchbox.indices.CreateIndex;
import io.searchbox.indices.DeleteIndex;
import io.searchbox.indices.IndicesExists;
import io.searchbox.indices.mapping.PutMapping;
/**
* An {@link IndexManager} applying indexing work to an Elasticsearch server.
*
* @author Gunnar Morling
*/
public class ElasticsearchIndexManager implements IndexManager, RemoteAnalyzerProvider {
private static final Log LOG = LoggerFactory.make( Log.class );
private static final String ANALYZED = "analyzed";
private String indexName;
private String actualIndexName;
private IndexManagementStrategy indexManagementStrategy;
private String indexManagementWaitTimeout;
/**
* Status the index needs to be at least in, otherwise we'll fail starting up.
*/
private IndexStatus requiredIndexStatus;
private Similarity similarity;
private ExtendedSearchIntegrator searchIntegrator;
private final Set<Class<?>> containedEntityTypes = new HashSet<>();
private ServiceReference<JestClient> clientReference;
private BackendQueueProcessor backend;
private LuceneWorkSerializer serializer;
private SerializationProvider serializationProvider;
private ServiceManager serviceManager;
private enum IndexStatus {
GREEN("green"),
YELLOW("yellow"),
RED("red");
private final String elasticsearchString;
private IndexStatus(String elasticsearchString) {
this.elasticsearchString = elasticsearchString;
}
public String getElasticsearchString() {
return elasticsearchString;
}
static IndexStatus fromString(String status) {
for ( IndexStatus indexStatus : IndexStatus.values() ) {
if ( indexStatus.getElasticsearchString().equalsIgnoreCase( status ) ) {
return indexStatus;
}
}
throw new SearchException( "Unexpected index status: " + status + ". Specify one of 'green', 'yellow' or 'red'." );
}
}
// Lifecycle
@Override
public void initialize(String indexName, Properties properties, Similarity similarity, WorkerBuildContext context) {
this.serviceManager = context.getServiceManager();
this.indexName = getIndexName( indexName, properties );
this.requiredIndexStatus = getRequiredIndexStatus( properties );
this.indexManagementStrategy = getIndexManagementStrategy( properties );
this.indexManagementWaitTimeout = getIndexManagementWaitTimeout( properties );
this.actualIndexName = IndexNameNormalizer.getElasticsearchIndexName( this.indexName );
this.similarity = similarity;
this.backend = BackendFactory.createBackend( this, context, properties );
}
private String getIndexName(String indexName, Properties properties) {
String name = properties.getProperty( Environment.INDEX_NAME_PROP_NAME );
return name != null ? name : indexName;
}
private IndexManagementStrategy getIndexManagementStrategy(Properties properties) {
String strategy = properties.getProperty( ElasticsearchEnvironment.INDEX_MANAGEMENT_STRATEGY );
return strategy != null ? IndexManagementStrategy.valueOf( strategy ) : ElasticsearchEnvironment.Defaults.INDEX_MANAGEMENT_STRATEGY;
}
private String getIndexManagementWaitTimeout(Properties properties) {
int timeout = ConfigurationParseHelper.getIntValue(
properties,
ElasticsearchEnvironment.INDEX_MANAGEMENT_WAIT_TIMEOUT,
ElasticsearchEnvironment.Defaults.INDEX_MANAGEMENT_WAIT_TIMEOUT
);
if ( timeout < 0 ) {
throw new SearchException( "Positive timeout value expected, but it was: " + timeout );
}
return timeout + "ms";
}
private IndexStatus getRequiredIndexStatus(Properties properties) {
String status = ConfigurationParseHelper.getString(
properties,
ElasticsearchEnvironment.REQUIRED_INDEX_STATUS,
ElasticsearchEnvironment.Defaults.REQUIRED_INDEX_STATUS
);
return IndexStatus.fromString( status );
}
@Override
public void destroy() {
if ( indexManagementStrategy == IndexManagementStrategy.CREATE_DELETE ) {
deleteIndexIfExisting();
}
backend.close();
clientReference.close();
}
@Override
public void setSearchFactory(ExtendedSearchIntegrator boundSearchIntegrator) {
this.searchIntegrator = boundSearchIntegrator;
this.clientReference = searchIntegrator.getServiceManager().requestReference( JestClient.class );
initializeIndex();
}
private void initializeIndex() {
if ( indexManagementStrategy == IndexManagementStrategy.NONE ) {
return;
}
else if ( indexManagementStrategy == IndexManagementStrategy.CREATE ||
indexManagementStrategy == IndexManagementStrategy.CREATE_DELETE ) {
deleteIndexIfExisting();
createIndex();
createIndexMappings();
}
else if ( indexManagementStrategy == IndexManagementStrategy.MERGE ) {
createIndexIfNotYetExisting();
createIndexMappings();
}
}
@Override
public void addContainedEntity(Class<?> entity) {
containedEntityTypes.add( entity );
}
private void createIndex() {
CreateIndex createIndex = new CreateIndex.Builder( actualIndexName )
.build();
clientReference.get().executeRequest( createIndex );
waitForIndexCreation();
}
private void waitForIndexCreation() {
Builder healthBuilder = new Health.Builder()
.setParameter( "wait_for_status", requiredIndexStatus.getElasticsearchString() )
.setParameter( "timeout", indexManagementWaitTimeout );
Health health = new Health( healthBuilder ) {
@Override
protected String buildURI() {
return super.buildURI() + actualIndexName;
}
};
JestResult result = clientReference.get().executeRequest( health, 408 );
if ( !result.isSucceeded() ) {
String status = result.getJsonObject().get( "status" ).getAsString();
throw new SearchException( "Index '" + actualIndexName + "' has status '" + status + "', but it is expected to be '"
+ requiredIndexStatus.getElasticsearchString() + "'." );
}
}
private void createIndexIfNotYetExisting() {
if ( clientReference.get().executeRequest( new IndicesExists.Builder( actualIndexName ).build(), 404 ).getResponseCode() == 200 ) {
return;
}
clientReference.get().executeRequest( new CreateIndex.Builder( actualIndexName ).build() );
}
private void deleteIndexIfExisting() {
// Not actually needed, but do it to avoid cluttering the ES log
if ( clientReference.get().executeRequest( new IndicesExists.Builder( actualIndexName ).build(), 404 ).getResponseCode() == 404 ) {
return;
}
try {
clientReference.get().executeRequest( new DeleteIndex.Builder( actualIndexName ).build() );
}
catch (SearchException e) {
// ignoring deletion of non-existing index
if ( !e.getMessage().contains( "index_not_found_exception" ) ) {
throw e;
}
}
}
// TODO HSEARCH-2260
// What happens if mappings already exist? We need an option similar to hbm2ddl
// What happens if several nodes in a cluster try to create the mappings?
private void createIndexMappings() {
for ( Class<?> entityType : containedEntityTypes ) {
EntityIndexBinding descriptor = searchIntegrator.getIndexBinding( entityType );
JsonObject payload = new JsonObject();
payload.addProperty( "dynamic", "strict" );
JsonObject properties = new JsonObject();
payload.add( "properties", properties );
// Add field for tenant id though we don't know at this point if it's actually going to be needed.
// TODO HSEARCH-2256 Should we make this configurable?
JsonObject field = new JsonObject();
field.addProperty( "type", "string" );
field.addProperty( "index", "not_analyzed" );
properties.add( DocumentBuilderIndexedEntity.TENANT_ID_FIELDNAME, field );
// normal document fields
for ( DocumentFieldMetadata fieldMetadata : descriptor.getDocumentBuilder().getTypeMetadata().getAllDocumentFieldMetadata() ) {
if ( fieldMetadata.isId() || fieldMetadata.getFieldName().isEmpty() || fieldMetadata.getFieldName().endsWith( "." )
|| fieldMetadata.isSpatial() ) {
continue;
}
addFieldMapping( payload, descriptor, fieldMetadata );
}
// bridge-defined fields
for ( BridgeDefinedField bridgeDefinedField : getAllBridgeDefinedFields( descriptor ) ) {
addFieldMapping( payload, bridgeDefinedField );
}
PutMapping putMapping = new PutMapping.Builder(
actualIndexName,
entityType.getName(),
payload
)
.build();
try {
clientReference.get().executeRequest( putMapping );
}
catch (Exception e) {
throw new SearchException( "Could not create mapping for entity type " + entityType.getName(), e );
}
}
}
private String analyzerName(Class<?> entityType, DocumentFieldMetadata fieldMetadata) {
AnalyzerReference analyzerReference = fieldMetadata.getAnalyzerReference();
if ( analyzerReference.is( RemoteAnalyzerReference.class ) ) {
return analyzerReference.unwrap( RemoteAnalyzerReference.class ).getAnalyzer().getName( fieldMetadata.getFieldName() );
}
LOG.analyzerIsNotRemote( entityType, fieldMetadata.getFieldName(), analyzerReference );
return null;
}
/**
* Adds a type mapping for the given field to the given request payload.
*/
private void addFieldMapping(JsonObject payload, EntityIndexBinding descriptor, DocumentFieldMetadata fieldMetadata) {
String simpleFieldName = FieldHelper.getEmbeddedFieldPropertyName( fieldMetadata.getName() );
JsonObject field = new JsonObject();
String fieldType = getFieldType( descriptor, fieldMetadata );
if ( fieldType == null ) {
LOG.debug( "Not adding a mapping for field " + fieldMetadata.getFieldName() + " as its type could not be determined" );
return;
}
field.addProperty( "type", fieldType );
field.addProperty( "store", fieldMetadata.getStore() == Store.NO ? false : true );
String index = getIndex( descriptor, fieldMetadata );
field.addProperty( "index", index );
String analyzerName = getAnalyzerName( descriptor, fieldMetadata, index );
if ( analyzerName != null ) {
field.addProperty( "analyzer", analyzerName );
}
if ( fieldMetadata.getBoost() != null ) {
field.addProperty( "boost", fieldMetadata.getBoost() );
}
if ( fieldMetadata.indexNullAs() != null ) {
// TODO HSEARCH-2262 Validate the type; Supported types are converted transparently by ES
field.addProperty( "null_value", fieldMetadata.indexNullAs() );
}
getOrCreateProperties( payload, fieldMetadata.getName() ).add( simpleFieldName, field );
// Create facet fields if needed: if the facet has the same name as the field, we don't need to create an
// extra field for it
for ( FacetMetadata facetMetadata : fieldMetadata.getFacetMetadata() ) {
if ( !facetMetadata.getFacetName().equals( fieldMetadata.getFieldName() ) ) {
addFieldMapping( payload, facetMetadata );
}
}
}
private String getAnalyzerName(EntityIndexBinding descriptor, DocumentFieldMetadata fieldMetadata, String index) {
if ( isAnalyzed( index ) && fieldMetadata.getAnalyzerReference() != null ) {
return analyzerName( descriptor.getDocumentBuilder().getBeanClass(), fieldMetadata );
}
return null;
}
private boolean isAnalyzed(String index) {
return ANALYZED.equals( index );
}
/**
* Adds a type mapping for the given field to the given request payload.
*/
private void addFieldMapping(JsonObject payload, BridgeDefinedField bridgeDefinedField) {
String fieldName = bridgeDefinedField.getName();
String simpleFieldName = FieldHelper.getEmbeddedFieldPropertyName( fieldName );
if ( !SpatialHelper.isSpatialField( simpleFieldName ) ) {
JsonObject field = new JsonObject();
field.addProperty( "type", getFieldType( bridgeDefinedField ) );
String index = getIndex( bridgeDefinedField );
field.addProperty( "index", index );
// we don't overwrite already defined fields. Typically, in the case of spatial, the geo_point field
// is defined before the double field and we want to keep the geo_point one
JsonObject parent = getOrCreateProperties( payload, fieldName );
if ( !parent.has( simpleFieldName ) ) {
parent.add( simpleFieldName, field );
}
}
else {
if ( SpatialHelper.isSpatialFieldLongitude( simpleFieldName ) ) {
// we ignore the longitude field, we will create the geo_point mapping only once with the latitude field
return;
}
else if ( SpatialHelper.isSpatialFieldLatitude( simpleFieldName ) ) {
// we only add the geo_point for the latitude field
JsonObject field = new JsonObject();
field.addProperty( "type", "geo_point" );
// in this case, the spatial field has precedence over an already defined field
getOrCreateProperties( payload, fieldName ).add( SpatialHelper.getSpatialFieldRootName( simpleFieldName ), field );
}
else {
// the fields potentially created for the spatial hash queries
JsonObject field = new JsonObject();
field.addProperty( "type", "string" );
field.addProperty( "index", "not_analyzed" );
getOrCreateProperties( payload, fieldName ).add( fieldName, field );
}
}
}
private JsonObject addFieldMapping(JsonObject payload, FacetMetadata facetMetadata) {
String simpleFieldName = FieldHelper.getEmbeddedFieldPropertyName( facetMetadata.getFacetName() );
String fullFieldName = facetMetadata.getFacetName();
JsonObject field = new JsonObject();
field.addProperty( "type", getFieldType( facetMetadata ) );
field.addProperty( "store", false );
field.addProperty( "index", "not_analyzed" );
getOrCreateProperties( payload, fullFieldName).add( simpleFieldName, field );
return field;
}
@SuppressWarnings("deprecation")
private String getIndex(EntityIndexBinding binding, DocumentFieldMetadata fieldMetadata) {
// Never analyze boolean, date or numeric
if ( FieldHelper.isBoolean( binding, fieldMetadata.getName() ) ||
FieldHelper.isDate( binding, fieldMetadata.getName() ) ||
FieldHelper.isCalendar( binding, fieldMetadata.getName() ) ||
FieldHelper.isNumeric(fieldMetadata) ) {
return "not_analyzed";
}
return getIndexValue( fieldMetadata.getIndex() );
}
@SuppressWarnings("deprecation")
private String getIndex(BridgeDefinedField bridgeDefinedField) {
// Never analyze boolean
if ( FieldHelper.isBoolean( bridgeDefinedField )
|| FieldHelper.isNumeric( bridgeDefinedField )
|| FieldHelper.isDate( bridgeDefinedField ) ) {
return "not_analyzed";
}
Field.Index index = bridgeDefinedField.getIndex();
return getIndexValue( index );
}
private String getIndexValue(Field.Index index) {
switch ( index ) {
case ANALYZED:
case ANALYZED_NO_NORMS:
return ANALYZED;
case NOT_ANALYZED:
case NOT_ANALYZED_NO_NORMS:
return "not_analyzed";
case NO:
return "no";
default:
throw new IllegalArgumentException( "Unexpected index type: " + index );
}
}
private String getFieldType(EntityIndexBinding descriptor, DocumentFieldMetadata fieldMetadata) {
String type;
if ( FieldHelper.isBoolean( descriptor, fieldMetadata.getName() ) ) {
type = "boolean";
}
else if ( FieldHelper.isDate( descriptor, fieldMetadata.getName() ) ||
FieldHelper.isCalendar( descriptor, fieldMetadata.getName() ) ) {
type = "date";
}
else if ( FieldHelper.isNumeric( fieldMetadata ) ) {
NumericEncodingType numericEncodingType = FieldHelper.getNumericEncodingType( descriptor, fieldMetadata );
switch ( numericEncodingType ) {
case INTEGER:
type = "integer";
break;
case LONG:
type = "long";
break;
case FLOAT:
type = "float";
break;
case DOUBLE:
type = "double";
break;
default:
// Likely a custom field bridge which does not expose the type of the given field; either correctly
// so (because the given name is the default field and this bridge does not wish to use that field
// name as is) or incorrectly; The field will not be added to the mapping, causing an exception at
// runtime if the bridge writes that field nevertheless
type = null;
}
}
else {
type = "string";
}
return type;
}
private String getFieldType(BridgeDefinedField bridgeDefinedField) {
switch ( bridgeDefinedField.getType() ) {
case BOOLEAN:
return "boolean";
case DATE:
return "date";
case FLOAT:
return "float";
case DOUBLE:
return "double";
case INTEGER:
return "integer";
case LONG:
return "long";
case STRING:
return "string";
default:
throw new SearchException( "Unexpected field type: " + bridgeDefinedField.getType() );
}
}
private String getFieldType(FacetMetadata facetMetadata) {
switch ( facetMetadata.getEncoding() ) {
case DOUBLE:
return "double";
case LONG:
return "long";
case STRING:
return "string";
case AUTO:
throw new AssertionFailure( "The facet type should have been resolved during bootstrapping" );
default: {
throw new AssertionFailure(
"Unexpected facet encoding type '"
+ facetMetadata.getEncoding()
+ "' Has the enum been modified?"
);
}
}
}
private JsonObject getOrCreateProperties(JsonObject mapping, String fieldName) {
if ( !FieldHelper.isEmbeddedField( fieldName ) ) {
return mapping.getAsJsonObject( "properties" );
}
JsonObject parentProperties = mapping.getAsJsonObject( "properties" );
String[] parts = fieldName.split( "\\." );
for ( int i = 0; i < parts.length - 1; i++ ) {
String part = parts[i];
JsonObject property = parentProperties.getAsJsonObject( part );
if ( property == null ) {
property = new JsonObject();
// TODO HSEARCH-2263 enable nested mapping as needed:
// * only needed for embedded *-to-many with more than one field
// * for these, the user should be able to opt out (nested would be the safe default mapping in this
// case, but they could want to opt out when only ever querying on single fields of the embeddable)
// property.addProperty( "type", "nested" );
JsonObject properties = new JsonObject();
property.add( "properties", properties );
parentProperties.add( part, property );
parentProperties = properties;
}
else {
parentProperties = property.getAsJsonObject( "properties" );
}
}
return parentProperties;
}
/**
* Recursively collects all the bridge-defined fields for the given type and its embeddables.
*/
private Set<BridgeDefinedField> getAllBridgeDefinedFields(EntityIndexBinding binding) {
Set<BridgeDefinedField> bridgeDefinedFields = new HashSet<>();
collectPropertyLevelBridgeDefinedFields( binding.getDocumentBuilder().getMetadata(), bridgeDefinedFields );
return bridgeDefinedFields;
}
private void collectPropertyLevelBridgeDefinedFields(TypeMetadata type, Set<BridgeDefinedField> allBridgeDefinedFields) {
allBridgeDefinedFields.addAll( type.getClassBridgeDefinedFields() );
if ( type.getIdPropertyMetadata() != null ) {
allBridgeDefinedFields.addAll( type.getIdPropertyMetadata().getBridgeDefinedFields().values() );
}
for ( PropertyMetadata property : type.getAllPropertyMetadata() ) {
allBridgeDefinedFields.addAll( property.getBridgeDefinedFields().values() );
}
for ( TypeMetadata embeddedType : type.getEmbeddedTypeMetadata() ) {
collectPropertyLevelBridgeDefinedFields( embeddedType, allBridgeDefinedFields );
}
}
// Getters
@Override
public String getIndexName() {
return indexName;
}
@Override
public ReaderProvider getReaderProvider() {
throw new UnsupportedOperationException( "No ReaderProvider / IndexReader with ES" );
}
@Override
public Set<Class<?>> getContainedTypes() {
return containedEntityTypes;
}
@Override
public Similarity getSimilarity() {
return similarity;
}
@Override
public Analyzer getAnalyzer(String name) {
return searchIntegrator.getAnalyzer( name );
}
@Override
public LuceneWorkSerializer getSerializer() {
if ( serializer == null ) {
serializationProvider = requestSerializationProvider();
serializer = new LuceneWorkSerializerImpl( serializationProvider, searchIntegrator );
LOG.indexManagerUsesSerializationService( this.indexName, this.serializer.describeSerializer() );
}
return serializer;
}
@Override
public void flushAndReleaseResources() {
// no-op
}
private SerializationProvider requestSerializationProvider() {
try {
return serviceManager.requestService( SerializationProvider.class );
}
catch (SearchException se) {
throw LOG.serializationProviderNotFoundException( se );
}
}
public String getActualIndexName() {
return actualIndexName;
}
// Runtime ops
@Override
public void performOperations(List<LuceneWork> queue, IndexingMonitor monitor) {
backend.applyWork( queue, monitor );
}
@Override
public void performStreamOperation(LuceneWork singleOperation, IndexingMonitor monitor, boolean forceAsync) {
backend.applyStreamWork( singleOperation, monitor );
}
@Override
public void optimize() {
performStreamOperation( OptimizeLuceneWork.INSTANCE, null, false );
}
@Override
public String toString() {
return "ElasticsearchIndexManager [actualIndexName=" + actualIndexName + "]";
}
@Override
public RemoteAnalyzer getRemoteAnalyzer(String name) {
return new RemoteAnalyzer( name );
}
@Override
public IndexManagerType getIndexManagerType() {
return ElasticsearchIndexManagerType.INSTANCE;
}
}