Skip to content

Commit f13dfcd

Browse files
committed
Merge branch 'master' into split_shards
2 parents be7ecd3 + cee9640 commit f13dfcd

File tree

45 files changed

+597
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+597
-329
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ If you have a bugfix or new feature that you would like to contribute to Elastic
3838

3939
We enjoy working with contributors to get their code accepted. There are many approaches to fixing a problem and it is important to find the best approach before writing too much code.
4040

41+
Note that it is unlikely the project will merge refactors for the sake of refactoring. These
42+
types of pull requests have a high cost to maintainers in reviewing and testing with little
43+
to no tangible benefit. This especially includes changes generated by tools. For example,
44+
converting all generic interface instances to use the diamond operator.
45+
4146
The process for contributing to any of the [Elastic repositories](https://github.com/elastic/) is similar. Details for individual projects can be found below.
4247

4348
### Fork and clone the repository

core/src/main/java/org/elasticsearch/Version.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public class Version implements Comparable<Version> {
9898
public static final Version V_5_6_2 = new Version(V_5_6_2_ID, org.apache.lucene.util.Version.LUCENE_6_6_1);
9999
public static final int V_5_6_3_ID = 5060399;
100100
public static final Version V_5_6_3 = new Version(V_5_6_3_ID, org.apache.lucene.util.Version.LUCENE_6_6_1);
101+
public static final int V_5_6_4_ID = 5060499;
102+
public static final Version V_5_6_4 = new Version(V_5_6_4_ID, org.apache.lucene.util.Version.LUCENE_6_6_1);
101103
public static final int V_6_0_0_alpha1_ID = 6000001;
102104
public static final Version V_6_0_0_alpha1 =
103105
new Version(V_6_0_0_alpha1_ID, org.apache.lucene.util.Version.LUCENE_7_0_0);
@@ -153,6 +155,8 @@ public static Version fromId(int id) {
153155
return V_6_0_0_alpha2;
154156
case V_6_0_0_alpha1_ID:
155157
return V_6_0_0_alpha1;
158+
case V_5_6_4_ID:
159+
return V_5_6_4;
156160
case V_5_6_3_ID:
157161
return V_5_6_3;
158162
case V_5_6_2_ID:

core/src/main/java/org/elasticsearch/common/util/concurrent/ThreadContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,10 @@ private ThreadContextStruct putHeaders(Map<String, String> headers) {
407407
if (headers.isEmpty()) {
408408
return this;
409409
} else {
410-
final Map<String, String> newHeaders = new HashMap<>();
410+
final Map<String, String> newHeaders = new HashMap<>(this.requestHeaders);
411411
for (Map.Entry<String, String> entry : headers.entrySet()) {
412412
putSingleHeader(entry.getKey(), entry.getValue(), newHeaders);
413413
}
414-
newHeaders.putAll(this.requestHeaders);
415414
return new ThreadContextStruct(newHeaders, responseHeaders, transientHeaders, isSystemContext);
416415
}
417416
}

core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
2828
import org.elasticsearch.common.xcontent.XContentHelper;
2929
import org.elasticsearch.common.xcontent.XContentParser;
30+
import org.elasticsearch.common.xcontent.XContentType;
3031
import org.elasticsearch.index.IndexSettings;
3132
import org.elasticsearch.index.mapper.DynamicTemplate.XContentFieldType;
3233
import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType;
@@ -58,9 +59,10 @@ ParsedDocument parseDocument(SourceToParse source) throws MapperParsingException
5859

5960
final Mapping mapping = docMapper.mapping();
6061
final ParseContext.InternalParseContext context;
61-
try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(), source.source())) {
62-
context = new ParseContext.InternalParseContext(indexSettings.getSettings(),
63-
docMapperParser, docMapper, source, parser);
62+
final XContentType xContentType = source.getXContentType();
63+
64+
try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(), source.source(), xContentType)) {
65+
context = new ParseContext.InternalParseContext(indexSettings.getSettings(), docMapperParser, docMapper, source, parser);
6466
validateStart(parser);
6567
internalParseDocument(mapping, context, parser);
6668
validateEnd(parser);
@@ -74,8 +76,7 @@ ParsedDocument parseDocument(SourceToParse source) throws MapperParsingException
7476

7577
reverseOrder(context);
7678

77-
ParsedDocument doc = parsedDocument(source, context, createDynamicUpdate(mapping, docMapper, context.getDynamicMappers()));
78-
return doc;
79+
return parsedDocument(source, context, createDynamicUpdate(mapping, docMapper, context.getDynamicMappers()));
7980
}
8081

8182
private static void internalParseDocument(Mapping mapping, ParseContext.InternalParseContext context, XContentParser parser) throws IOException {
@@ -89,7 +90,7 @@ private static void internalParseDocument(Mapping mapping, ParseContext.Internal
8990
// entire type is disabled
9091
parser.skipChildren();
9192
} else if (emptyDoc == false) {
92-
parseObjectOrNested(context, mapping.root, true);
93+
parseObjectOrNested(context, mapping.root);
9394
}
9495

9596
for (MetadataFieldMapper metadataMapper : mapping.metadataMappers) {
@@ -338,7 +339,7 @@ private static ObjectMapper createUpdate(ObjectMapper parent, String[] nameParts
338339
return parent.mappingUpdate(mapper);
339340
}
340341

341-
static void parseObjectOrNested(ParseContext context, ObjectMapper mapper, boolean atRoot) throws IOException {
342+
static void parseObjectOrNested(ParseContext context, ObjectMapper mapper) throws IOException {
342343
if (mapper.isEnabled() == false) {
343344
context.parser().skipChildren();
344345
return;
@@ -467,7 +468,7 @@ private static ParseContext nestedContext(ParseContext context, ObjectMapper map
467468

468469
private static void parseObjectOrField(ParseContext context, Mapper mapper) throws IOException {
469470
if (mapper instanceof ObjectMapper) {
470-
parseObjectOrNested(context, (ObjectMapper) mapper, false);
471+
parseObjectOrNested(context, (ObjectMapper) mapper);
471472
} else {
472473
FieldMapper fieldMapper = (FieldMapper)mapper;
473474
Mapper update = fieldMapper.parse(context);
@@ -481,14 +482,13 @@ private static void parseObjectOrField(ParseContext context, Mapper mapper) thro
481482
private static void parseObject(final ParseContext context, ObjectMapper mapper, String currentFieldName) throws IOException {
482483
assert currentFieldName != null;
483484

484-
Mapper objectMapper = getMapper(mapper, currentFieldName);
485+
final String[] paths = splitAndValidatePath(currentFieldName);
486+
Mapper objectMapper = getMapper(mapper, currentFieldName, paths);
485487
if (objectMapper != null) {
486488
context.path().add(currentFieldName);
487489
parseObjectOrField(context, objectMapper);
488490
context.path().remove();
489491
} else {
490-
491-
final String[] paths = splitAndValidatePath(currentFieldName);
492492
currentFieldName = paths[paths.length - 1];
493493
Tuple<Integer, ObjectMapper> parentMapperTuple = getDynamicParentMapper(context, paths, mapper);
494494
ObjectMapper parentMapper = parentMapperTuple.v2();
@@ -518,7 +518,9 @@ private static void parseObject(final ParseContext context, ObjectMapper mapper,
518518

519519
private static void parseArray(ParseContext context, ObjectMapper parentMapper, String lastFieldName) throws IOException {
520520
String arrayFieldName = lastFieldName;
521-
Mapper mapper = getMapper(parentMapper, lastFieldName);
521+
522+
final String[] paths = splitAndValidatePath(arrayFieldName);
523+
Mapper mapper = getMapper(parentMapper, lastFieldName, paths);
522524
if (mapper != null) {
523525
// There is a concrete mapper for this field already. Need to check if the mapper
524526
// expects an array, if so we pass the context straight to the mapper and if not
@@ -529,8 +531,6 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
529531
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
530532
}
531533
} else {
532-
533-
final String[] paths = splitAndValidatePath(arrayFieldName);
534534
arrayFieldName = paths[paths.length - 1];
535535
lastFieldName = arrayFieldName;
536536
Tuple<Integer, ObjectMapper> parentMapperTuple = getDynamicParentMapper(context, paths, parentMapper);
@@ -589,12 +589,12 @@ private static void parseValue(final ParseContext context, ObjectMapper parentMa
589589
if (currentFieldName == null) {
590590
throw new MapperParsingException("object mapping [" + parentMapper.name() + "] trying to serialize a value with no field associated with it, current value [" + context.parser().textOrNull() + "]");
591591
}
592-
Mapper mapper = getMapper(parentMapper, currentFieldName);
592+
593+
final String[] paths = splitAndValidatePath(currentFieldName);
594+
Mapper mapper = getMapper(parentMapper, currentFieldName, paths);
593595
if (mapper != null) {
594596
parseObjectOrField(context, mapper);
595597
} else {
596-
597-
final String[] paths = splitAndValidatePath(currentFieldName);
598598
currentFieldName = paths[paths.length - 1];
599599
Tuple<Integer, ObjectMapper> parentMapperTuple = getDynamicParentMapper(context, paths, parentMapper);
600600
parentMapper = parentMapperTuple.v2();
@@ -607,7 +607,7 @@ private static void parseValue(final ParseContext context, ObjectMapper parentMa
607607

608608
private static void parseNullValue(ParseContext context, ObjectMapper parentMapper, String lastFieldName) throws IOException {
609609
// we can only handle null values if we have mappings for them
610-
Mapper mapper = getMapper(parentMapper, lastFieldName);
610+
Mapper mapper = getMapper(parentMapper, lastFieldName, splitAndValidatePath(lastFieldName));
611611
if (mapper != null) {
612612
// TODO: passing null to an object seems bogus?
613613
parseObjectOrField(context, mapper);
@@ -893,15 +893,15 @@ private static Tuple<Integer, ObjectMapper> getDynamicParentMapper(ParseContext
893893
break;
894894
case FALSE:
895895
// Should not dynamically create any more mappers so return the last mapper
896-
return new Tuple<Integer, ObjectMapper>(pathsAdded, parent);
896+
return new Tuple<>(pathsAdded, parent);
897897

898898
}
899899
}
900900
context.path().add(paths[i]);
901901
pathsAdded++;
902902
parent = mapper;
903903
}
904-
return new Tuple<Integer, ObjectMapper>(pathsAdded, mapper);
904+
return new Tuple<>(pathsAdded, mapper);
905905
}
906906

907907
// find what the dynamic setting is given the current parse context and parent
@@ -929,8 +929,7 @@ private static ObjectMapper.Dynamic dynamicOrDefault(ObjectMapper parentMapper,
929929
}
930930

931931
// looks up a child mapper, but takes into account field names that expand to objects
932-
static Mapper getMapper(ObjectMapper objectMapper, String fieldName) {
933-
String[] subfields = splitAndValidatePath(fieldName);
932+
private static Mapper getMapper(ObjectMapper objectMapper, String fieldName, String[] subfields) {
934933
for (int i = 0; i < subfields.length - 1; ++i) {
935934
Mapper mapper = objectMapper.getMapper(subfields[i]);
936935
if (mapper == null || (mapper instanceof ObjectMapper) == false) {

core/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
5454
public static final int DEFAULT_MAX_EXPANSIONS = FuzzyQuery.defaultMaxExpansions;
5555

5656
/** Default as to whether transpositions should be treated as a primitive edit operation,
57-
* instead of classic Levenshtein algorithm. Defaults to false. */
58-
public static final boolean DEFAULT_TRANSPOSITIONS = false;
57+
* instead of classic Levenshtein algorithm. Defaults to true. */
58+
public static final boolean DEFAULT_TRANSPOSITIONS = FuzzyQuery.defaultTranspositions;
5959

6060
private static final ParseField TERM_FIELD = new ParseField("term");
6161
private static final ParseField VALUE_FIELD = new ParseField("value");
@@ -74,7 +74,6 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
7474

7575
private int maxExpansions = DEFAULT_MAX_EXPANSIONS;
7676

77-
//LUCENE 4 UPGRADE we need a testcase for this + documentation
7877
private boolean transpositions = DEFAULT_TRANSPOSITIONS;
7978

8079
private String rewrite;

core/src/main/java/org/elasticsearch/ingest/ConfigurationUtils.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
3232
import java.util.Collections;
33+
import java.util.HashMap;
3334
import java.util.List;
3435
import java.util.Map;
3536

@@ -294,13 +295,13 @@ public static ElasticsearchException newConfigurationException(String processorT
294295
return exception;
295296
}
296297

297-
public static List<Processor> readProcessorConfigs(List<Map<String, Map<String, Object>>> processorConfigs,
298+
public static List<Processor> readProcessorConfigs(List<Map<String, Object>> processorConfigs,
298299
Map<String, Processor.Factory> processorFactories) throws Exception {
299300
Exception exception = null;
300301
List<Processor> processors = new ArrayList<>();
301302
if (processorConfigs != null) {
302-
for (Map<String, Map<String, Object>> processorConfigWithKey : processorConfigs) {
303-
for (Map.Entry<String, Map<String, Object>> entry : processorConfigWithKey.entrySet()) {
303+
for (Map<String, Object> processorConfigWithKey : processorConfigs) {
304+
for (Map.Entry<String, Object> entry : processorConfigWithKey.entrySet()) {
304305
try {
305306
processors.add(readProcessor(processorFactories, entry.getKey(), entry.getValue()));
306307
} catch (Exception e) {
@@ -353,13 +354,28 @@ private static void addHeadersToException(ElasticsearchException exception, Stri
353354
}
354355
}
355356

357+
@SuppressWarnings("unchecked")
358+
public static Processor readProcessor(Map<String, Processor.Factory> processorFactories,
359+
String type, Object config) throws Exception {
360+
if (config instanceof Map) {
361+
return readProcessor(processorFactories, type, (Map<String, Object>) config);
362+
} else if (config instanceof String && "script".equals(type)) {
363+
Map<String, Object> normalizedScript = new HashMap<>(1);
364+
normalizedScript.put(ScriptType.INLINE.getName(), config);
365+
return readProcessor(processorFactories, type, normalizedScript);
366+
} else {
367+
throw newConfigurationException(type, null, null,
368+
"property isn't a map, but of type [" + config.getClass().getName() + "]");
369+
}
370+
}
371+
356372
public static Processor readProcessor(Map<String, Processor.Factory> processorFactories,
357373
String type, Map<String, Object> config) throws Exception {
358374
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
359375
Processor.Factory factory = processorFactories.get(type);
360376
if (factory != null) {
361377
boolean ignoreFailure = ConfigurationUtils.readBooleanProperty(null, null, config, "ignore_failure", false);
362-
List<Map<String, Map<String, Object>>> onFailureProcessorConfigs =
378+
List<Map<String, Object>> onFailureProcessorConfigs =
363379
ConfigurationUtils.readOptionalList(null, null, config, Pipeline.ON_FAILURE_KEY);
364380

365381
List<Processor> onFailureProcessors = readProcessorConfigs(onFailureProcessorConfigs, processorFactories);

core/src/main/java/org/elasticsearch/ingest/Pipeline.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public static final class Factory {
118118
public Pipeline create(String id, Map<String, Object> config, Map<String, Processor.Factory> processorFactories) throws Exception {
119119
String description = ConfigurationUtils.readOptionalStringProperty(null, null, config, DESCRIPTION_KEY);
120120
Integer version = ConfigurationUtils.readIntProperty(null, null, config, VERSION_KEY, null);
121-
List<Map<String, Map<String, Object>>> processorConfigs = ConfigurationUtils.readList(null, null, config, PROCESSORS_KEY);
121+
List<Map<String, Object>> processorConfigs = ConfigurationUtils.readList(null, null, config, PROCESSORS_KEY);
122122
List<Processor> processors = ConfigurationUtils.readProcessorConfigs(processorConfigs, processorFactories);
123-
List<Map<String, Map<String, Object>>> onFailureProcessorConfigs =
123+
List<Map<String, Object>> onFailureProcessorConfigs =
124124
ConfigurationUtils.readOptionalList(null, null, config, ON_FAILURE_KEY);
125125
List<Processor> onFailureProcessors = ConfigurationUtils.readProcessorConfigs(onFailureProcessorConfigs, processorFactories);
126126
if (config.isEmpty() == false) {

0 commit comments

Comments
 (0)