add clear when deleting an index for the field data service

This commit is contained in:
Shay Banon 2013-01-18 14:34:28 +01:00
parent a39ca58de9
commit 692413862a
2 changed files with 19 additions and 16 deletions

View File

@ -43,6 +43,7 @@ import org.elasticsearch.index.codec.CodecModule;
import org.elasticsearch.index.engine.IndexEngine;
import org.elasticsearch.index.engine.IndexEngineModule;
import org.elasticsearch.index.fielddata.IndexFieldDataModule;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.flush.FlushStats;
import org.elasticsearch.index.gateway.IndexGateway;
import org.elasticsearch.index.gateway.IndexGatewayModule;
@ -346,6 +347,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
indexInjector.getInstance(PercolatorService.class).close();
indexInjector.getInstance(IndexCache.class).close();
indexInjector.getInstance(IndexFieldDataService.class).clear();
indexInjector.getInstance(AnalysisService.class).close();
indexInjector.getInstance(IndexEngine.class).close();
indexInjector.getInstance(IndexServiceManagement.class).close();

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.facet.FacetCollector;
@ -119,22 +120,6 @@ public class RangeFacetProcessor extends AbstractComponent implements FacetProce
RangeFacet.Entry[] rangeEntries = entries.toArray(new RangeFacet.Entry[entries.size()]);
// fix the range entries if needed
if (keyField != null) {
FieldMapper mapper = context.smartNameFieldMapper(keyField);
if (mapper == null) {
throw new FacetPhaseExecutionException(facetName, "No mapping found for key_field [" + keyField + "]");
}
for (RangeFacet.Entry entry : rangeEntries) {
if (entry.fromAsString != null) {
entry.from = ((Number) mapper.value(entry.fromAsString)).doubleValue();
}
if (entry.toAsString != null) {
entry.to = ((Number) mapper.value(entry.toAsString)).doubleValue();
}
}
}
if (keyScript != null && valueScript != null) {
return new ScriptRangeFacetCollector(facetName, scriptLang, keyScript, valueScript, params, rangeEntries, context);
}
@ -143,6 +128,22 @@ public class RangeFacetProcessor extends AbstractComponent implements FacetProce
throw new FacetPhaseExecutionException(facetName, "key field is required to be set for range facet, either using [field] or using [key_field]");
}
// we have a keyField
FieldMapper keyFieldMapper = context.smartNameFieldMapper(keyField);
if (keyFieldMapper == null) {
throw new FacetPhaseExecutionException(facetName, "No mapping found for key_field [" + keyField + "]");
}
for (RangeFacet.Entry entry : rangeEntries) {
if (entry.fromAsString != null) {
entry.from = ((Number) keyFieldMapper.value(entry.fromAsString)).doubleValue();
}
if (entry.toAsString != null) {
entry.to = ((Number) keyFieldMapper.value(entry.toAsString)).doubleValue();
}
}
IndexNumericFieldData keyIndexFieldData = context.fieldData().getForField(keyFieldMapper.names(), keyFieldMapper.fieldDataType2());
if (valueField == null || keyField.equals(valueField)) {
return new RangeFacetCollector(facetName, keyField, rangeEntries, context);
} else {