Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share numeric date analyzer instances between mappings #6843

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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) {
Expand Down
Expand Up @@ -186,9 +186,8 @@ protected DateFieldMapper(Names names, FormatDateTimeFormatter dateTimeFormatter
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;
Expand Down
Expand Up @@ -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", "");
Expand Down