Share numeric data analyzer instances between mappings
use similar mechanism that shares numeric analyzers for long/double/... for dates as well. This has nice memory save properties with many date fields mapping case, as well as analysis saves (thread local resources) closes #6843
This commit is contained in:
parent
e764c5f08a
commit
9345194a65
|
@ -19,18 +19,41 @@
|
|||
|
||||
package org.elasticsearch.index.analysis;
|
||||
|
||||
import com.carrotsearch.hppc.IntObjectOpenHashMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentMapLong;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class NumericDateAnalyzer extends NumericAnalyzer<NumericDateTokenizer> {
|
||||
|
||||
private final int precisionStep;
|
||||
private static final Map<String, IntObjectOpenHashMap<NamedAnalyzer>> globalAnalyzers = Maps.newHashMap();
|
||||
|
||||
public static synchronized NamedAnalyzer buildNamedAnalyzer(FormatDateTimeFormatter formatter, int precisionStep) {
|
||||
IntObjectOpenHashMap<NamedAnalyzer> precisionMap = globalAnalyzers.get(formatter.format());
|
||||
if (precisionMap == null) {
|
||||
precisionMap = new IntObjectOpenHashMap<>();
|
||||
globalAnalyzers.put(formatter.format(), precisionMap);
|
||||
}
|
||||
NamedAnalyzer namedAnalyzer = precisionMap.get(precisionStep);
|
||||
if (namedAnalyzer == null) {
|
||||
String name = "_date/" + ((precisionStep == Integer.MAX_VALUE) ? "max" : precisionStep);
|
||||
namedAnalyzer = new NamedAnalyzer(name, AnalyzerScope.GLOBAL, new NumericDateAnalyzer(precisionStep, formatter.parser()));
|
||||
precisionMap.put(precisionStep, namedAnalyzer);
|
||||
}
|
||||
return namedAnalyzer;
|
||||
}
|
||||
|
||||
private final int precisionStep;
|
||||
private final DateTimeFormatter dateTimeFormatter;
|
||||
|
||||
public NumericDateAnalyzer(int precisionStep, DateTimeFormatter dateTimeFormatter) {
|
||||
|
|
|
@ -186,9 +186,8 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
|
|||
PostingsFormatProvider postingsProvider, DocValuesFormatProvider docValuesProvider, SimilarityProvider similarity,
|
||||
|
||||
Loading normsLoading, @Nullable Settings fieldDataSettings, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
|
||||
super(names, precisionStep, boost, fieldType, docValues, ignoreMalformed, coerce, new NamedAnalyzer("_date/" + precisionStep,
|
||||
new NumericDateAnalyzer(precisionStep, dateTimeFormatter.parser())),
|
||||
new NamedAnalyzer("_date/max", new NumericDateAnalyzer(Integer.MAX_VALUE, dateTimeFormatter.parser())),
|
||||
super(names, precisionStep, boost, fieldType, docValues, ignoreMalformed, coerce, NumericDateAnalyzer.buildNamedAnalyzer(dateTimeFormatter, precisionStep),
|
||||
NumericDateAnalyzer.buildNamedAnalyzer(dateTimeFormatter, Integer.MAX_VALUE),
|
||||
postingsProvider, docValuesProvider, similarity, normsLoading, fieldDataSettings, indexSettings, multiFields, copyTo);
|
||||
this.dateTimeFormatter = dateTimeFormatter;
|
||||
this.nullValue = nullValue;
|
||||
|
|
|
@ -82,7 +82,7 @@ public class ManyMappingsBenchmark {
|
|||
private static final String TYPE_NAME = "type";
|
||||
private static final int FIELD_COUNT = 100000;
|
||||
private static final int DOC_COUNT = 10000000;
|
||||
private static final boolean TWO_NODES = false;
|
||||
private static final boolean TWO_NODES = true;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("es.logger.prefix", "");
|
||||
|
|
Loading…
Reference in New Issue